在命令行上通过管道输入条件
我有一个问题,我不知道这是否可能。我正在解析一个包含文件名的文件,并想检查这些文件名是否代表系统中的现有文件。
我找到了检查文件是否存在的可能性:
[ -f FILENAME ] && echo "File exists" || echo "File does not exists"
现在我的问题是:我如何通过管道输入它测试所有文件名的条件?
我正在尝试像 tihs 一样,但它不起作用:
cat myfilenames.txt |上面的 xargs 命令不带 FILENAME
有人知道这是否可能吗?
谢谢,dmeu!
I have a problem i could not figure out if it's even possible. I am parsing a file with filenames in it, and want to check if those filenames represent an existing file within the system.
i figured out a possibility to to check if a file exists:
[ -f FILENAME ] && echo "File exists" || echo "File does not exists"
now my problem is: How can i pipe into to the conditional that it tests for all the filenames?
i was trying like tihs, but it did not work:
cat myfilenames.txt | xargs command from above without FILENAME
does anybody know if it is possible?
thanks, dmeu!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信你想要的是一个for循环。这在 bash 中对我有用(我把它放在 shell 脚本中,但你可能可以在命令行上执行):
cat 周围的反引号执行命令并将输出替换到循环中。
I believe what you want is a for loop. This worked for me in bash (I put it in a shell script, but you could probably do it on the command line):
the backticks around the cat execute the command and substitute the output into the loop.