LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 02-11-2010, 06:11 PM   #1
nyheat
Member
 
Registered: Aug 2005
Distribution: Debian
Posts: 75

Rep: Reputation: 15
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?
 
Old 02-12-2010, 12:19 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Stretch (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
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.
 
1 members found this post helpful.
Old 02-12-2010, 01:11 AM   #3
Web31337
Member
 
Registered: Sep 2009
Location: Russia
Distribution: Gentoo, LFS
Posts: 399
Blog Entries: 71

Rep: Reputation: 65
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.
 
Old 02-12-2010, 01:14 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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
 
1 members found this post helpful.
Old 02-12-2010, 02:08 AM   #5
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
symbolic link not allowed or link target not accessible paullaubscher Linux - Newbie 4 03-10-2010 06:47 AM
symbolic link manolakis Linux - Newbie 1 05-08-2008 07:40 PM
How to create symbolic link to html file and avoid page link problem? haxpor Linux - General 2 01-29-2008 07:40 AM
Symbolic link? jasone Linux - Newbie 4 05-06-2005 07:55 AM
symbolic link jsetter Linux - Newbie 4 11-22-2004 07:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration