← Back to context

Comment by chasil

5 hours ago

My initial syntax does work in dash (and bash), but all these shells appear to rely on expanding ~ inside a word, that your source asserts is not POSIX (which I do not contest).

Perhaps a succinct and compliant expression could be:

  export PATH="$PATH:$(printf %s ~/.local/bin)"

That comes at the cost of forking a subsell.

Edit: 2.6.1 Tilde Expansion in the POSIX standard says that ~ may be expanded "following any unquoted <colon>".

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V...

That being so, the most succinct and compliant version is my first variant, with the colon moved outside the quotes:

  export PATH="$PATH":~/.local/bin

Thank you for prompting me to look this up.