Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-30-2010
vistastar's Avatar
Registered User
 

Join Date: Jul 2010
Location: Galaxy
Posts: 169
Thanks: 5
Thanked 7 Times in 7 Posts
Puzzled with hexdump, hd and ln

How to create a symbolic link to a command with certain argument?

When I man hexdump, it is said in the man page that "-C Canonical hex+ASCII display...Calling the command hd implies this option". Actually it is. hd equals to hexdump -C.

And then I examined the ln command but find it is a symbolic link to hexdump, just like this: /usr/bin/hd -> hexdump.

But I failed to make such a symbolic link like this. I tried: ln -s "/bin/ls -al" myls. But it didn't work.

I wonder how to make a symbolic link to a command with certain argument.

Thanks.
Sponsored Links
    #2  
Old 07-30-2010
pludi's Avatar
pludi pludi is offline Forum Staff  
Cat herder
 

Join Date: Dec 2008
Location: Vienna, Austria, Earth
Posts: 5,486
Thanks: 38
Thanked 324 Times in 301 Posts
Short answer: you can't

Long answer: A symbolic link is just a reference to a different file. Basically it tells the OS "You were looking for file x, but to use it please load file y". However, since every program is told it's execution name as the very first parameter (even before those you specify on the command line), it can use different behaviour based on that name. But the program itself has to support that, and short of modifying the source you can't change the behaviour.

What you can do instead is create an alias:
Code:
alias myls="/bin/ls -la"

The Following User Says Thank You to pludi For This Useful Post:
vistastar (07-30-2010)
Sponsored Links
    #3  
Old 07-30-2010
ygemici ygemici is online now Forum Advisor  
sed_shell@LNU
 

Join Date: Feb 2010
Location: istanbul
Posts: 1,478
Thanks: 1
Thanked 247 Times in 240 Posts
Additional you can only like this so you cant not set options with command because this change the directive and there is no `ls -la`


Code:
# ln -s "/bin/ls" myls
# ./myls

The Following User Says Thank You to ygemici For This Useful Post:
vistastar (07-30-2010)
    #4  
Old 07-30-2010
vistastar's Avatar
Registered User
 

Join Date: Jul 2010
Location: Galaxy
Posts: 169
Thanks: 5
Thanked 7 Times in 7 Posts
@pludi:

Thank you. That's interesting. I notice that the utility BusyBox behaves in the way you mentioned.


Code:
lrwxrwxrwx    1 1004     1004            7 Jan  1 00:00 chgrp -> busybox
lrwxrwxrwx    1 1004     1004            7 Jan  1 00:00 chmod -> busybox
lrwxrwxrwx    1 1004     1004            7 Jan  1 00:00 chown -> busybox
lrwxrwxrwx    1 1004     1004            7 Jan  1 00:00 cp -> busybox


But, does the ln command have nothing to do with this feature? Is it only a trick of the program linked?

Last edited by pludi; 07-31-2010 at 07:49 AM.. Reason: code tags, please...
Sponsored Links
    #5  
Old 07-31-2010
pludi's Avatar
pludi pludi is offline Forum Staff  
Cat herder
 

Join Date: Dec 2008
Location: Vienna, Austria, Earth
Posts: 5,486
Thanks: 38
Thanked 324 Times in 301 Posts
No, the ln command has nothing to do with it. The only thing it really does is call the symlink or link function, plus some validation. After all, a program is just a file, like a text file or image.
Sponsored Links
    #6  
Old 07-31-2010
Moderator
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 12,191
Thanks: 232
Thanked 1,703 Times in 1,632 Posts
Quote:
Originally Posted by vistastar View Post
@pludi:

Thank you. That's interesting. I notice that the utility BusyBox behaves in the way you mentioned.
It does, and it doesn't. Busybox can detect what name it's called with and act accordingly; a trick its developers exploited to squeeze dozens of utilities into one medium executable. What you don't see happening is any arguments in those links. As described previously, that has to be done in the shell.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reverse hexdump without xxd LessNux Shell Programming and Scripting 3 03-17-2010 01:02 AM
Puzzled over over the relationship between the partition and geometry of hard disk. just.srad Solaris 5 12-08-2008 07:49 PM
puzzled with VxVM and iostat.. samar Solaris 1 09-28-2008 09:18 AM
C++ Puzzled !! RipClaw Programming 1 04-17-2005 11:18 PM
Puzzled with user ID. lethefe Programming 4 07-15-2003 10:39 AM



All times are GMT -4. The time now is 04:00 AM.