11 ms·
Additionally, $ f=-x $ cat "$f" cat: invalid option -- 'x' $ cat -- "$f" cat: -x: No such file or directory # ^-- correct, but: $
by mgdlbp 3y ago
Additionally,
$ f=-x
$ cat "$f"
cat: invalid option -- 'x'
$ cat -- "$f"
cat: -x: No such file or directory
# ^-- correct, but:
$ f=-
$ cat -- "$f"
reading stdin...
reading stdin...
^C
$ f=./-
$ cat -- "$f"
cat: ./-: No such file or directory
...better to glob with ./* than *
- pjot 3y agoAlso for sanitizing user input. input=$1 # User input, potentially dangerous rm $input # Incorrect: Risky if input contains something like '*' rm "$input" # Correct: Safer, treats the user input as a single item