Using an alias in find -exec

前端 未结 7 682
醉酒成梦
醉酒成梦 2021-01-07 19:11

I have a very long command in bash, which I do not want to type all the time, so I put an alias in my .profile

alias foo=\'...\'

Now I want

7条回答
  •  逝去的感伤
    2021-01-07 20:03

    It's not possible (or difficult / error-prone) to use aliases in the find command. An easier way to achieve the desired result is putting the contents of the alias in a shellscript and run that shellscript:

    alias foo | sed "s/alias foo='//;s/'$/ \"\$@\"/" > /tmp/foo
    find -exec bash /tmp/foo {} \;
    

    The sed command removes the leading alias foo=' and replaces the trailing ' by "$@" which will contain the arguments passed to the script.

提交回复
热议问题