问题描述
我试图运行下面的命令:
I'm trying to run the following command:
find . -iname '.#*' -print0 | xargs -0 -L 1 foobar
,其中foobar的是一个别名,或在我的.bashrc文件中定义函数(对我来说,这是一个函数,它接受一个参数)。显然xargs的不承认这些东西因为它可以运行。有一个聪明的办法来解决这个问题?
where "foobar" is an alias or function defined in my .bashrc file (in my case, it's a function that takes one parameter). Apparently xargs doesn't recognize these as things it can run. Is there a clever way to remedy this?
推荐答案
因为只有你的交互shell知道别名,为什么不只是运行的别名,而无需通过的xargs
分叉?
Since only your interactive shell knows about aliases, why not just run the alias without forking out through xargs
?
find . -iname '.#*' -print0 | while read -r -d '' i; do foobar "$i"; done
如果您确信您的文件名没有在他们换行符(益,为什么他们会?),可以简化这
If you're sure that your filenames don't have newlines in them (ick, why would they?), you can simplify this to
find . -iname '.#*' -print | while read -r i; do foobar "$i"; done
甚至只是找到-iname'#*。| ...
,因为默认目录为。
键,默认操作是 -print
or even just find -iname '.#*' | ...
, since the default directory is .
and the default action is -print
.
还有一个选择:
IFS=$'\n'; for i in `find -iname '.#*'`; do foobar "$i"; done
告诉巴什说的话只在新行拆分(默认值: IFS = $'\\ t \\ n'
)。你应该小心,虽然;某些脚本不应付好一个改变 $ IFS
。
telling Bash that words are only split on newlines (default: IFS=$' \t\n'
). You should be careful with this, though; some scripts don't cope well with a changed $IFS
.
这篇关于xargs的不承认bash的别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!