What is tilde (~) in Mac/Linux?

The tilde(~) expansion in Mac/Linux has several pathnames.[ref]GNU Bash: Tilde Expansion[/ref][ref] The Magic ~: Bash Tilde Expansion with 5 Examples [/ref]

  • It could be ${HOME} if you do not specify the username.
    If you specify the user, it will expend the home directory of the user.
    For example,

    $ echo ~
    /Users/yourusername
    $ echo ~otheruser
    /Users/otheruser
  • It contains the working directory by +/-
    For example,

    $ echo ~+
    /Users/current_directory
    $ echo ~-
    /Users/old/previous_directory

In shell, if you want to expand it,

EXPAND_PATH=`eval echo ~otheruse/bin/`

Leave a Reply

Your email address will not be published. Required fields are marked *

Threesome