logoalt Hacker News

paulddraper • today at 2:11 PM • 1 reply • view on HN

That's standard POSIX.

Tilde expands when at the beginning of an unquoted word.

Pretty straightforward.

  ~ or ~/ --> $HOME

  ~user --> user's home
---

Bash has a few extra.

  ~+ --> $PWD

  ~- --> $OLDPWD

  ~+N or ~-N --> dirs

Replies

Joel_Mckay • today at 2:31 PM

In most use cases, the bash scripts location is more important than $HOME. This is because it is resilient to changes in user in the session, and parent process current working location contexts. =3

scriptPath=$(/usr/bin/realpath "${BASH_SOURCE[0]}")

localPath=$(/usr/bin/dirname "$scriptPath" )

/usr/bin/echo "localPath = '$localPath'"