Thursday, August 23, 2007

All your base...

Master Ian (whom I would link to, if his blog were not continually DOWN), showed me a very simple yet useful command: basename.

You give it the path to a file, it gives you the filename and extension. If you also give it the extension, it just gives you the filename. Thus:
sam@ZenSam:~$ basename unique-ip-list.csv
unique-ip-list.csv
sam@ZenSam:~$ basename unique-ip-list.csv .csv
unique-ip-list
This could be quite useful in shell scripting, to grab a list of desired for various purposes. One implementation I thought of right off: If you wanted to throw an error message for the usage of a command in a script, instead of having it display "See /usr/bin/zip for details" or something similar, you could run it through basename, and get a better looking name.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home