Saturday 28 January 2012

basename


basename
 basename is used to get the name of the file given its complete path including the file.
It is also  helpful to access the name of  a script within it.


Ex ample1)
To get the name of a file from its complete path.
/home/gj876$ echo $CGI_PATH
/utilities/intranet/apache/cgi-docs/cowboy
/home/gj876$ basename $CGI_PATH
cowboy


Example2)
Suppose a script “/home/scripts/linkfiles.sh” is called from   another script with its complete path,then to access the  base filename of  “/home/scripts/linkfiles.sh”, use
#!/usr/bin/ksh
File_name=`basename $0`
echo $File_name

the output will be linkfiles.sh

No comments:

Post a Comment