初学shell,很多不懂,所以将自己在实际中用到的都记录下来,希望高手们多给宝贵意见,谢谢
#!/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