mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2147 (markdown)
23
SC2147.md
Normal file
23
SC2147.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
## Literal tilde in PATH works poorly across programs.
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
PATH="$PATH:~/bin"
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
PATH="$PATH:$HOME/bin"
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
Having literal `~` in PATH is a bad idea. Bash handles it, but nothing else does.
|
||||||
|
|
||||||
|
This means that even if you're always using Bash, you should avoid it because any invoked program that relies on PATH will effectively ignore those entries.
|
||||||
|
|
||||||
|
For example, `make` may say `foo: Command not found` even though `foo` works fine from the shell and Make and Bash both use the same PATH. You'll get similar messages from any non-bash scripts invoked, and `whereis` will come up empty.
|
||||||
|
|
||||||
|
Use `$HOME` or full path instead.
|
||||||
|
|
||||||
|
### Contraindications
|
||||||
|
|
||||||
|
If your directory name actually contains a literal tilde, you can ignore this message.
|
Reference in New Issue
Block a user