Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-11-2010, 07:11 PM   #1
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, 01:19 AM   #2
Senior Member
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
No, the symbolic link is just a representation of the path.

You could consider using an alias instead, eg:
alias script1='./script -somecommand'
Or as you suggest, use a second script.
1 members found this post helpful.
Old 02-12-2010, 02:11 AM   #3
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, 02:14 AM   #4
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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:
c@CW8:/tmp$ cat
case "${0##*/}" in )
                echo "I'm doing bar stuff"
                ;; )
                echo "I'm doing foo stuff"
                ;; )
                echo "I'm doing test stuff"
    * )
                echo "I don't know who I am. Exiting" >&2
                exit 1

exit 0

c@CW8:/tmp$ ln -s
c@CW8:/tmp$ ln -s
c@CW8:/tmp$ ln -s
c@CW8:/tmp$ ./
I'm doing bar stuff
c@CW8:/tmp$ ./
I'm doing foo stuff
c@CW8:/tmp$ ./
I'm doing test stuff
c@CW8:/tmp$ ./
I don't know who I am. Exiting
1 members found this post helpful.
Old 02-12-2010, 03:08 AM   #5
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
to PATH=$PATH:$HOME/bin:~/script

Last edited by r3sistance; 02-12-2010 at 07:27 AM. Reason: Directory, not file


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 07:47 AM
symbolic link manolakis Linux - Newbie 1 05-08-2008 08:40 PM
How to create symbolic link to html file and avoid page link problem? haxpor Linux - General 2 01-29-2008 08:40 AM
Symbolic link? jasone Linux - Newbie 4 05-06-2005 08:55 AM
symbolic link jsetter Linux - Newbie 4 11-22-2004 08:18 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:46 AM.

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