我希望命令
ls -d doc/* | grep -P "<some_pattern>" | xargs bash -ic echo
做到与:
ls -d doc/* | grep -P "<some_pattern>" | xargs echo
也就是说,要给我匹配的文件ls -d doc/* | grep -P "<some_pattern>"
,仅用空格而不是换行符分隔。
但是我只能得到换行符作为输出。
为什么是这样?如何修复第一个命令以执行所需的操作?
顺便说一句,我正在实现使用zsh
而不是bash
,但是两者都行不通。
我实际上需要使用它来打印一堆文件,这些文件的名称与“ grep”指定的模式匹配,并且应该使用.zshrc
-aliased命令打印。
从bash手册页
-c string If the -c option is present, then commands are read from
string. If there are arguments after the string, they are
assigned to the positional parameters, starting with $0.
所以...
$ echo a b c d e f g | xargs bash -ic echo
$ echo a b c d e f g | xargs bash -ic 'echo $0 $@'
a b c d e f g
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句