~/
is only one of several magical "Tilde Expansions". Tilde expansions are particularly associated with UNIX shells. Unlike $HOME
tilde expansions are not universally understood and can vary shell by shell. The only commonality is adherence to the POSIX standard (for the most part), and according to Wikipedia the POSIX shell standard is based on a "strict subset" of the Korn Shell, a derivative of the Bourne Shell. Descendants of the Bourne shell notably include bash and zsh. Here's what POSIX says about Tilde Expansions:
A "tilde-prefix" consists of an unquoted character at the
beginning of a word, followed by all of the characters preceding the
first unquoted in the word, or all the characters in the word
if there is no . In an assignment (see XBD Variable
Assignment), multiple tilde-prefixes can be used: at the beginning of
the word (that is, following the of the assignment),
following any unquoted , or both. A tilde-prefix in an
assignment is terminated by the first unquoted or . If
none of the characters in the tilde-prefix are quoted, the characters
in the tilde-prefix following the are treated as a possible
login name from the user database. A portable login name cannot
contain characters outside the set given in the description of the
LOGNAME environment variable in XBD Other Environment Variables. If
the login name is null (that is, the tilde-prefix contains only the
tilde), the tilde-prefix is replaced by the value of the variable
HOME. If HOME is unset, the results are unspecified. Otherwise, the
tilde-prefix shall be replaced by a pathname of the initial working
directory associated with the login name obtained using the getpwnam()
function as defined in the System Interfaces volume of POSIX.1-2008.
If the system does not recognize the login name, the results are
undefined.
The pathname resulting from tilde expansion shall be treated as if
quoted to prevent it being altered by field splitting and pathname
expansion.
Basically that means ~
gives the $HOME and ~foo/
links to the initial working directory of user foo. Roughly but not always meaning the home directory of foo. (the only exception I can think of is root)
In BaSH they don't adhere to that standard for tilde expansions in a few ways, none particularly significant. BaSH also has other fun tilde expansions, link courtesy of commenter @phk. You can collect them all!
But I digress. If we're talking about what ~/ is called, I'm not sure if you're referring to the term for the path itself (of the form ~/x/y/z
) or for the phenomena of using ~/
to make said path (ie, artwork vs art, derivative vs differentiation). Because ~/ paths
and ~/ expanded paths
seem to refer to the former and ~/ syntax
and ~/ notation
to the latter. I'm probably overcomplicating but language is a fickle thing. For instance~/ paths
emphasizes the form of the paths as beginning with ~/
, while ~/ extended paths
emphasizes the function ~/
is performing to create the path of that form.
Anyway, by now you've probably realized that
there is no accepted name
since all of those terms are in circulation and the issue hasn't been given official attention that we know of from the powers that be. Or to put it differently, all of those terms are ways of describing the same thing- not competing labels. They have no formal name but anyone who knows a bit of bash will immediately recognize what they mean- and if people understand what you're talking about, who cares what you call it? You can decide for yourself which term you like. Personally I like ~/ paths
, pronounced "tilde-slash paths". And to refer to the phenomena "tilde-slash path shorthand". To be honest I don't even think they need a name...
~
’), all of the characters up to the first unquoted slash (or all characters, if there is no unquoted slash) are considered a tilde-prefix. If none of the characters in the tilde-prefix are quoted, the characters in the tilde-prefix following the tilde are treated as a possible login name. If this login name is the null string, the tilde is replaced with the value of theHOME
shell variable. …". Apparently things are more complicated than they seem? – phk Oct 31 '16 at 22:05