Linux 多行命令与 for
我想测试和比较两个文件夹中的文件。为此,我使用了下一个命令
for FILE in folder_one/*; do
test -f folder_one_arch/$FILE && echo $FILE " exists" || echo $FILE " not exists"
cmp -s $FILE folder_one_arch/$FILE && echo "same" || echo "different";
done
,但该命令不起作用,问题出在哪里?
I want to test and compare files in two folders. For this purpose, I used the next command
for FILE in folder_one/*; do
test -f folder_one_arch/$FILE && echo $FILE " exists" || echo $FILE " not exists"
cmp -s $FILE folder_one_arch/$FILE && echo "same" || echo "different";
done
but this command is not working, from where is the problem occuring?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题来自
$FILE
:它包含您期望文件时的路径。我建议您采用以下方法:有两个变量,
PATH
(它是for
循环中的变量)和FILE
(它只是文件基名)。请参阅https://mywiki.wooledge.org/BashFAQ/073
The problem comes from
$FILE
: it contains a path while you were expecting a file.I propose you the following approach: have two variables,
PATH
which is the variable in thefor
loop andFILE
which is only the file basename.See https://mywiki.wooledge.org/BashFAQ/073