What is tilde (~) in Mac/Linux?

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

  • 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/`

You May Also Like

Leave a Reply

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