mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2088 (markdown)
21
SC2088.md
21
SC2088.md
@@ -1,4 +1,4 @@
|
|||||||
## Note that ~ doesn't expand in quotes.
|
## Tilde does not expand in quotes. Use $HOME.
|
||||||
|
|
||||||
### Problematic code:
|
### Problematic code:
|
||||||
|
|
||||||
@@ -6,26 +6,13 @@
|
|||||||
|
|
||||||
### Correct code:
|
### Correct code:
|
||||||
|
|
||||||
rm ~/"Desktop/$filename"
|
rm "$HOME/Desktop/$filename"
|
||||||
|
|
||||||
### Rationale:
|
### Rationale:
|
||||||
|
|
||||||
Tilde does not expand to the user's home directory when it's double quoted.
|
Tilde does not expand to the user's home directory when it's single or double quoted. Use double quotes and `$HOME` instead.
|
||||||
|
|
||||||
To expand it, the tilde, the optional username, and its following slash should be outside of the double quotes.
|
Alternatively, the `~/` can be left unquoted, as in `rm ~/"Desktop/$filename"`.
|
||||||
|
|
||||||
These strings expand:
|
|
||||||
|
|
||||||
~/file # Correct: tilde up to the slash is unquoted (everything is)
|
|
||||||
~/"$var" # Correct: tilde up to the slash is unquoted
|
|
||||||
~user/"hello world.txt" # Correct: tilde up to the slash is unquoted
|
|
||||||
|
|
||||||
These strings do not, leaving a literal tilde:
|
|
||||||
|
|
||||||
# Fails!
|
|
||||||
"~/file" # Wrong: tilde and slash are quoted when they shouldn't be.
|
|
||||||
~"/file" # Wrong: slash is quoted when it shouldn't be.
|
|
||||||
~user"/hello world.txt" # Wrong: slash is quoted when it shouldn't be.
|
|
||||||
|
|
||||||
### Exceptions
|
### Exceptions
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user