Skip to content

Latest commit

 

History

History
28 lines (16 loc) · 754 Bytes

SC2142.md

File metadata and controls

28 lines (16 loc) · 754 Bytes

Pattern: Use of alias with positional parameter

Issue: -

Description

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.

Example of incorrect code:

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

Example of correct code:

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

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}' "$@"; }

Further Reading