Skip to content
koalaman edited this page Jan 20, 2018 · 6 revisions

Aliases can't use positional parameters. Use a function.

Problematic code:

alias archive='mv "$@" /backup'

Correct code:

archive() { mv "$@" /backup; }

Rationale:

Aliases just substitute the start of a command with something else. They therefore can't use positional parameters, such as $1. Rewrite your alias as a function.

Exceptions

If your alias ends up quoting the value, e.g. alias cut_first="awk '{print \$1}'", you can technically ignore this error. However, you should consider turning this alias into a more readable function instead: cut_first() { awk '{print $1}' "$@"; }

Related resources:

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally