Section 7.8. Tilde Substitution


[Page 267]

7.8. Tilde Substitution

Any token of the form ~name is subject to tilde substitution. The shell checks the password file to see if name is a valid user name, and if it is, replaces the ~name sequence with the full pathname of the user's home directory. If it isn't, the ~name sequence is left unchanged. Tilde substitution occurs after aliases are processed. Figure 7-16 is a table of the tilde substitutions, including the special cases ~+ and ~-.

Figure 7-16. Tilde substitutions in the Korn shell.

Tilde sequence

Replaced by

~

$HOME

~user

home directory of user

~/pathname

$HOME/pathname

~+

$PWD (current working directory)

~-

$OLDPWD (previous working directory)


The predefined local variables PWD and OLDPWD are described later in this chapter. Here are some examples of tilde substitution:

$ pwd /home/glass        ...current working directory. $ echo ~ /home/glass        ...my home directory. $ cd /             ...change to root directory. $ echo ~+ /                  ...current working directory. $ echo ~- /home/glass        ...previous working directory. $ echo ~dcox /home/dcox         ...another user's home directory. $ _ 





Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net