Tilde Substitution

   

Korn Shell: Unix and Linux Programming Manual, Third Edition, The
By Anatole Olczak

Table of Contents
Chapter 2.  Korn Shell Basics


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  $ pwd  /home/users/admin/smith/tools 

If the tilde character is followed by a + or ?/span>, it is replaced with the value of PWD (current directory) and OLDPWD (previous directory), respectively. This is not very useful for directory navigation, since cd ~+ leaves you in the current directory. The cd ~?/span> command puts you in the previous directory, but the Korn shell provides an even shorter shortcut: cd ?/span> does the same thing, except that it also displays the current directory.

 $ pwd  /home/users/admin/smith/tools  $ cd /usr/bin  $ cd ~- $ pwd  /home/users/admin/smith/tools  $ cd - /usr/bin 

Table 2.7. Tilde Substitution

~

replaced with $HOME

~user

replaced with the home directory of user

~?/span>

replaced with $OLDPWD (previous directory)

~+

replaced with $PWD (current directory)


       
    Top
     



    Korn Shell. Unix and Linux Programming Manual, Third Edition
    Korn Shell. Unix and Linux Programming Manual, Third Edition
    ISBN: N/A
    EAN: N/A
    Year: 2000
    Pages: 177

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