Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
To make a script you can take cat `which zcat` or cat `which gunzip` for instance. That's what can be used globally instead of aliases, but both methods are good.
Another solution is to have multiple symlinks (or hard links) to a single script and program it to behave differently depending on which name it is called with:
Code:
c@CW8:/tmp$ cat test.sh
#!/bin/bash
case "${0##*/}" in
bar.sh )
echo "I'm doing bar stuff"
;;
foo.sh )
echo "I'm doing foo stuff"
;;
test.sh )
echo "I'm doing test stuff"
;;
* )
echo "I don't know who I am. Exiting" >&2
exit 1
esac
exit 0
c@CW8:/tmp$ ln -s test.sh bar.sh
c@CW8:/tmp$ ln -s test.sh foo.sh
c@CW8:/tmp$ ln -s test.sh wibble.sh
c@CW8:/tmp$ ./bar.sh
I'm doing bar stuff
c@CW8:/tmp$ ./foo.sh
I'm doing foo stuff
c@CW8:/tmp$ ./test.sh
I'm doing test stuff
c@CW8:/tmp$ ./wibble.sh
I don't know who I am. Exiting
Another potential thing you could do also is make a scripts directory like ~/scripts/ and add it to the $PATH variable, if you make the scripts executable (with chmod).
I am not sure where ubuntu stores such a place where this can be added. In CentOS it can be done in ~/.bash_profile by modifying the line
PATH=$PATH:$HOME/bin
to PATH=$PATH:$HOME/bin:~/script
Last edited by r3sistance; 02-12-2010 at 06:27 AM.
Reason: Directory, not file
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.