Aliases can't use positional parametersSH-2142
Aliases just substitute the start of a command with something else.
They therefore can't use positional parameters, such as $1
.
Please rewrite your alias as a function.
Bad Practice
alias archive='mv "$@" /backup'
Recommended:
archive() { mv "$@" /backup; }
Exceptions
If your alias ends up quoting the value, e.g. alias cut_first="awk '{print \$1}'"
, you can ignore this issue.
However, you should consider turning this alias into a more readable function instead: cut_first() { awk '{print $1}' "$@"; }
.
You can also ignore this issue if you intentionally referenced the positional parameters of its relevant context, knowing that it won't refer to the parameters of the alias itself.
For example:
alias whatisthis='echo "This is $0 -$-" #'
will show the shell name with flags, i.e. This is dash -smi
or This is bash -himBs
, and is correct usage because it does not intend for $0
to reflect anything related to the whatisthis
alias or its invocation.