by paulddraper · 1mo ago · 0 comments
GENERAL RULE
1. Double-quote dollar sign expressions, and nothing else.
foo
"$bar"/foo
baz:"$(cat example.txt)"
exec cmd "$@"
2. Single-quote words with a literal special character, and nothing else. 'Die Hard'
'ke$ha'
---I should point out that the author's example is NOT fixed by different quoting though.
# original
export PATH="$PATH:~/.local/bin/"
# without unnecessary quotes
export PATH="$PATH":~/.local/bin/
Because tilde expansion only happens at the beginning of the word.Sure, but I would say you almost always want to add to the start of the PATH, not to the end.
path=( $path ~/bin )
It's worth noting, also, that the path and manpath settings in login.conf(5) expand leading tildes in individual search path items.* https://man.freebsd.org/cgi/man.cgi?query=login.conf&sektion...
So putting the addition of things like ~/bin to PATH in /etc/login_conf and ~/.login_conf instead of shell scripts is another way to address it.
:path=~/bin /usr/local/bin /usr/pkg/bin /usr/bin /bin:
It's particularly handy when there are multiple login shells in use.> Because tilde expansion only happens at the beginning of the word.
Nope, works fine:
$ PATH=/bin/
$ export PATH="$PATH":~/.local/bin
$ echo $PATH
/bin/:/home/izkata/.local/bin
I guess it's being smart about the ":" since this doesn't work: $ PATH=/bin/
$ export PATH="$PATH":foo/~/.local/bin
$ echo $PATH
/bin/:foo/~/.local/bin
And even just putting the ":" inside the quotes and "~" outside doesn't work: $ PATH=/bin/
$ export PATH="$PATH:"~/.local/bin
$ echo $PATH
/bin/:~/.local/bin