繁体   English   中英

如何遍历从命令行给出的目录中的文件?

[英]How do I loop through files in a directory given from the command line?

我正在尝试从命令行构建一个脚本。 但是每次我运行时,我的 echo 命令只打印目录名称而不是目录中的文件。

for EachFile in $1:
do
  #Do stuff
  echo "Filename is $EachFile"

done

冒号在路径中没有特殊含义。 使用全局:

for file in "$1"/* ; do
    printf '%s\n' "$file"
done

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM