Tilde Substitution

Tilde substitution is used to substitute the pathname of a user's home directory for user. Words in the command line that start with the tilde character cause the Korn shell to check the rest of the word up to a slash. If the tilde character is found alone or is only followed by a slash, it is replaced with the value of the HOME variable. This is a handy shortcut borrowed from the C shell. For example, to print the pathname of your home directory:

					$ echo ∼
					/home/anatole
				

or to list its contents:

					$ ls ∼/
					NEWS         bin         pc
					asp          mail        src
				

If the tilde character is followed by a login name file, it is replaced with the home directory of that user. Here we change directory to the tools directory in smith's home directory:

					$ cd ∼smith/tools ...

Get Korn Shell: Unix and Linux Programming Manual, Third Edition, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.