O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

basename

Format:

basename path 

Basename will strip the path from a supplied pathname and return just the filename. Commonly used in usage statements in scripts, in this case substitution is used when echoing out the filename.

					$ basename /home/dave/myscript 
myscript
				
echo "Usage: ` basename $0 ` give me a file " exit 1 ...

If the above was part of a script called myscript, the output would be,

myscript: give me a file

The $0 is a special variable that holds the current full pathname of the script.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required