问题shell脚本如何遍历文件夹下所有文件?
方法:
dir="./sql_to_hdfs_init"
for file in `ls $dir/*`
do
echo $file # 输出 ./sql_to_hdfs_init/a.sh
if test -f $file;then # 相当于 if [ -f $file ];then
echo "执行:$file"
fi
done
注:ls ./sql_to_hdfs_init 这个可以查询到文件夹下所有文件名
ls ./sql_to_hdfs_init/* 这个可以查询到文件夹下所有文件,包括文件路径
参考:
https://blog.csdn.net/fl1623863129/article/details/116642093