for file in $(ls ${targetPath})
do
file $file
done
为什么提示No such file of directory?
for file in $(ls ${targetPath})
do
file $file
done
为什么提示No such file of directory?
让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言问题分析: 在上述代码中,通过ls命令获取${targetPath}路径下的所有文件名,并将文件名赋值给file变量,然后对每个文件进行判断。 出现No such file or directory提示的原因有可能是${targetPath}路径下不存在任何文件,或者${targetPath}路径不存在。 解决方案:
ls ${targetPath}
for file in ${targetPath}/*
do
file $file
done
这样可以直接获取${targetPath}路径下的所有文件,并避免No such file or directory错误。