mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2142 (markdown)
18
SC2142.md
Normal file
18
SC2142.md
Normal file
@@ -0,0 +1,18 @@
|
||||
## 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.
|
||||
|
||||
### Contraindications
|
||||
|
||||
None.
|
Reference in New Issue
Block a user