I have following line in my .zshrc
file:
alias clean="sed -i 's/\r//g; s/ /\t/g' $(find . -maxdepth 1 -type f)"
but when I try to execute it in /path/to/some/directory
the output is:
sed ./.Xauthority
./.lesshst: No such file or directory
.Xauthority
and .lesshst
are both in my home directory.
Substitutiong .
with $(pwd)
dos not help.
When defining the alias you've used double quotes to encompass the entire (alias) definition. This has the effect of actually running the
find
command at the time the alias is defined.So when the alias is created it will pick up a list of files from the directory in which the alias is being defined (eg, in your home directory when sourcing
.zshrc
).You can see this happening in the following example:
Notice how the
find
was evaluated at alias definition time and pulled in all of the files in my/tmp
directory.To address this issue you want to make sure the
find
is not evaluated at the time the alias is created.There are a few ways to do this, one idea being to wrap the
find
portion of the definition in single quotes, another idea would be keep the current double quotes and just escape the$
, eg:Notice in both cases the alias contains the actual
find
command instead of the results of evaluating it in the current directory.