使用read
例如 如下内容的test.sh
#!/bin/sh
while read line ; do
echo $line
done
[root@imos controllers]# ls -al | sh test.sh
total 28
drwxr-xr-x 3 apache apache 4096 Apr 6 08:40 .
drwxr-xr-x 16 apache apache 4096 Apr 5 17:26 ..
-rw-r--r-- 1 apache apache 114 Apr 5 17:26 index.html
-rw-r--r-- 1 apache apache 859 Apr 5 17:59 summary.php
drwxr-xr-x 6 apache apache 4096 Apr 5 17:26 .svn
-rw-r--r-- 1 root root 53 Apr 6 08:39 test.sh
-rw-r--r-- 1 apache apache 770 Apr 5 17:26 welcome.php