LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Symbolic link with commands? (https://www.linuxquestions.org/questions/linux-newbie-8/symbolic-link-with-commands-788550/)

nyheat 02-11-2010 06:11 PM

Symbolic link with commands?
 
Is it possible to create a symbolic link that include commands for the program?

For instance, I do the following to start the program:

./script -somecommannd

I would like to create a symbolic like that includes "-somecommand"

Is this possible? or would I need to create a second script that executes that command, and link to that script?

neonsignal 02-12-2010 12:19 AM

No, the symbolic link is just a representation of the path.

You could consider using an alias instead, eg:
Code:

alias script1='./script -somecommand'
Or as you suggest, use a second script.

Web31337 02-12-2010 01:11 AM

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.

catkin 02-12-2010 01:14 AM

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


r3sistance 02-12-2010 02:08 AM

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


All times are GMT -5. The time now is 05:09 PM.