-
http://www.2cto.com/os/201302/190701.html
-
Shell(Bash) 编程实例之获取某个文件夹下的所有文件名(含文件夹)初学shell,很多不懂,所以将自己在实际中用到的都记录下来,希望高手们多给宝贵意见,谢谢 www.2cto.com[plain]#!/bin/sh#============ get the file name ===========Folder_A="/home/youname/shell/gotfilename/bin"for file_a in ${Folder_A}/*; dotemp_file=`basename $file_a`echo $temp_filedone如果要输出到一个文件的话也可以重定向到一个文件中去修改为:[plain]#!/bin/sh#============ get the file name ===========Folder_A="/home/Neo/shell/gotfilename/bin"Output_file="output.txt"#这里用于清空原本的输出文件,感觉 : 这个符号用处挺大,shell的学习还是要多用才是 www.2cto.com: > $Output_filefor file_a in ${Folder_A}/*; dotemp_file=`basename $file_a`echo $temp_file >> $Output_filedone更新(20130222日)--------增加了交互性[ html]#!/bin/sh#============ get the file name ===========echo -e "请输入你要读取的文件夹路径\n当前路径为${PWD}"read InputDirecho "你输入的文件夹路径为${InputDir}"echo -e "请输入你要将数据输出保存的文件路径n当前路径为${PWD}"read OutputFileecho "输出保存的文件路径为${OutputFile}": > $OutputFile #清空OutputFile#循环读取文件夹名for file_a in ${InputDir}/*; dotemp_file=`basename $file_a`echo $temp_file >> $OutputFiledone似乎用 命令行配合正则表达式实现起来更好
Shell(Bash)编程实例之获取某个文件夹下的所有文件名(含文件夹)
最新推荐文章于 2023-08-05 15:52:00 发布