http://blog.csdn.net/backgarden_straw/article/details/8599618
- #!/bin/sh
- #============ get the file name ===========
- Folder_A="/home/youname/shell/gotfilename/bin"
- for file_a in ${Folder_A}/*; do
- temp_file=`basename $file_a`
- echo $temp_file
- done
修改为:
- #!/bin/sh
- #============ get the file name ===========
- Folder_A="/home/Neo/shell/gotfilename/bin"
- Output_file="output.txt"
- #这里用于清空原本的输出文件,感觉 : 这个符号用处挺大,shell的学习还是要多用才是
- : > $Output_file
- for file_a in ${Folder_A}/*; do
- temp_file=`basename $file_a`
- echo $temp_file >> $Output_file
- done
更新(20130222日)--------增加了交互性
- #!/bin/sh
- #============ get the file name ===========
- echo -e "请输入你要读取的文件夹路径\n当前路径为${PWD}"
- read InputDir
- echo "你输入的文件夹路径为${InputDir}"
- echo -e "请输入你要将数据输出保存的文件路径n当前路径为${PWD}"
- read OutputFile
- echo "输出保存的文件路径为${OutputFile}"
- : > $OutputFile #清空OutputFile
- #循环读取文件夹名
- for file_a in ${InputDir}/*; do
- temp_file=`basename $file_a`
- echo $temp_file >> $OutputFile
- done