Sams Teach Yourself Shell Programming in (Web site templates) 24 Hours
Sams Teach Yourself Shell Programming in 24 Hours Contents Index Hour 24: Shell Programming FAQs Previous Chapter Next Chapter Sections in this Chapter: Shell and Command Questions File and Directory Questions Variable and Argument Questions Summary Previous Section Next Section File and Directory Questions In this section, I will look at some questions about files and directories. These questions include issues with specific commands and examples that illustrate the usage of commands to solve particular problems. How do I determine the full pathname of a directory? Shell scripts that work with directories often need to determine the full pathname of a directory to perform the correct operations on these directories. You can determine the full pathname of a directory by using the cd and pwd commands: FULLPATH= (cd dir ; pwd) Here dir is the name of a directory. This command changes directories to the specified directory, dir, and then displays the full pathname of the directory using the pwd command. Because command substitution is used, the full pathname is assigned to the variable FULLPATH. Because the cd command changes the working directory of the current shell, you execute it in a subshell. Thus the working directory of the shell script is unchanged. How do I determine the full pathname of a file? Determining the full pathname of a file is slightly harder than determining the full pathname of a directory. You need to use the dirname and basename commands in conjunction with the cd and pwd commands to determine the full pathname of a file: CURDIR= pwd cd dirname file FULLPATH=” pwd / basename file ” cd $CURDIR Here file is the name of a file whose full pathname you want to determine. First you save the current path of the current directory in the variable CURDIR. Next you change to the directory containing the specified file, file. Then you join the output of the pwd command and the name of the file determined using the basename command to get the full pathname. This value gets stored in the variable FULLPATH. Finally you change back to the original directory. How can locate a particular file?
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.