xargs doesn't recognize bash aliases

后端 未结 6 522
猫巷女王i
猫巷女王i 2020-12-13 03:21

I\'m trying to run the following command:

find . -iname \'.#*\' -print0 | xargs -0 -L 1 foobar

where \"foobar\" is an alias or function def

6条回答
  •  庸人自扰
    2020-12-13 04:08

    I usually use find like this:

    find . -iname '' -exec cmd '{}' \;
    

    '{}' will get replaced with the filename, and \; is necessary to terminate the execution chain. However, if that doesn't work with your function, you might need to run it through bash:

    find .. |sed -e "s/.*/cmd '&'/"|bash
    

    Find prints each file on a line, sed just prefixes this with your command, and then pipe it to bash for execution. Skip the |bash first to see what will happen.

提交回复
热议问题