环境准备:
[root@nodchen-db01-test day07]# mkdir -p /server/scripts/day07/test/{test.txt,oldboy.txt,oldgirl.txt}
drwxr-xr-x 5 root root 4096 Jul 24 19:56 test
[root@nodchen-db01-test day07]# cd test/
[root@nodchen-db01-test test]#
[root@nodchen-db01-test test]# ll
total 12
drwxr-xr-x 2 root root 4096 Jul 24 19:56 oldboy.txt
drwxr-xr-x 2 root root 4096 Jul 24 19:56 oldgirl.txt
drwxr-xr-x 2 root root 4096 Jul 24 19:56 test.txt
脚本内容如下:
cd /server/scripts/day07/test/
for filename in `ls`
do
echo $filename
done
运行结果:
[root@nodchen-db01-test day07]# sh 11_3_1.sh
oldboy.txt
oldgirl.txt
test.txt