[SOLVED] Use of cmd=`basename $0` in shell scripting
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I have seen in many shell scripts, the variable used cmd=`basename $0`
What's use of this variable in a shell script? Is it necessory?
Though I've read one thread on the same, but that was not so informative.
So please give your expert opinions.
Thanks in advance!
Thanks for clearing that up, that explains why most of where I've seen basename used is in init scripts. They don't have file extensions and it may be necessary to call back to what service is being started/stopped.
As long as you use Bash you are right, no need for basename. But many scripts are written POSIX compliant, which doesn't nknow of that substitution features of Bash (and other shells). So if you aim at portability basename is the preferred solution.