检查循环中的文件是否是目录时出现问题
此代码是检查路径是否为目录的工作示例:
if [ -d "$1" ]; then
printf "Directory exists\n"
else
printf "Does not exists\n"
fi
我将其更改为此以尝试测试目录中的文件是否为目录:
for file in "$1/*"; do
if [ -d "$file" ]; then
printf "Directory: %s\n" $file
else
printf "File: %s\n" $file
fi
done
但它不起作用 - 目录显示为就好像它们是文件一样。为什么它不起作用?我怎样才能让这段代码做我想做的事?
干杯。
This code is a working example of checking if a path is a directory:
if [ -d "$1" ]; then
printf "Directory exists\n"
else
printf "Does not exists\n"
fi
I changed it to this to try and test if files in a directory are directories or not:
for file in "$1/*"; do
if [ -d "$file" ]; then
printf "Directory: %s\n" $file
else
printf "File: %s\n" $file
fi
done
But it does not work - directories are displayed as if they were files. Why wont it work? And how can I get this code to do what I want?
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能引用星号。
You can't quote the asterisk.