Boo*_*jaa 0 unix linux bash pipe sh
每当我执行输出多行的linux命令时,我想对输出的每一行执行一些操作.我一般都这么做
command something | while read a
do
some operation on $a;
done
Run Code Online (Sandbox Code Playgroud)
这很好用.但我的问题是,是否有一些我可以通过预定义的符号访问每一行(不知道如何调用它)///像$这样的东西?..或.. $!..或.. $ _
有可能吗?
cat to_be_removed.txt | rm -f $LINE
Run Code Online (Sandbox Code Playgroud)
在bash中有预定义的$ LINE ..或者前一个是最短的方式.即.
cat to_be_removed.txt | while read line; do rm -f $line; done;
Run Code Online (Sandbox Code Playgroud)
xargs 正是你要找的:
cat to_be_removed.txt | xargs rm -f
Run Code Online (Sandbox Code Playgroud)
但是,如果使用那个文件名,请注意文件名中的空格.查看xargs手册页以获取更多信息.
| 归档时间: |
|
| 查看次数: |
434 次 |
| 最近记录: |