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
findcommand 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
findwas evaluated at alias definition time and pulled in all of the files in my/tmpdirectory.To address this issue you want to make sure the
findis not evaluated at the time the alias is created.There are a few ways to do this, one idea being to wrap the
findportion 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
findcommand instead of the results of evaluating it in the current directory.