Puzzled with hexdump, hd and ln


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Puzzled with hexdump, hd and ln
# 1  
Old 07-30-2010
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.
# 2  
Old 07-30-2010
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"

This User Gave Thanks to pludi For This Post:
# 3  
Old 07-30-2010
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

This User Gave Thanks to ygemici For This Post:
# 4  
Old 07-30-2010
@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 08:49 AM.. Reason: code tags, please...
# 5  
Old 07-31-2010
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.
# 6  
Old 08-01-2010
Quote:
Originally Posted by vistastar
@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.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

Serioulsy puzzled here.

Facebook had a mathematics problem which was as thus:- 6/2(1+2) = ? Answer is 9. My ancient Casio FX 730P mini computer written exactly as that gives 'error' only. Now take a look at shell versions, and a python version:- Last login: Wed Sep 14 18:04:04 on ttys000 AMIGA:barrywalker~>... (6 Replies)
Discussion started by: wisecracker
6 Replies

2. Shell Programming and Scripting

How to perform a hexdump using dd from start point to end point?

hi, I would like to ask or is it possible to dump a hex using dd from starting point to end point just like the "xxd -s 512 -l 512 <bin file>" I know the redirect hexdump -C but i can't figure it out the combination options of dd. Hope someone can share their knowledge.. Thanks in... (3 Replies)
Discussion started by: jao_madn
3 Replies

3. OS X (Apple)

Puzzled by Find

I'm new to playing with the command line on OS X and am puzzled by the response I am getting from the find command. I have a file structure similar to the following /Volumes/ ../Drobo/ ../../Pictures/ ../../../Image 1/ ../../../../Image 1.jpg ../../../../Previews/ ../../../../../Image... (2 Replies)
Discussion started by: Denrael
2 Replies

4. Shell Programming and Scripting

Reverse hexdump without xxd

The "hexdump" command cannot perform reverse operation. On the other hand, the "xxd" command with -r option performs reverse hexdump, while the "xxd" command without -r performs the (forward) hexdump. An example of hexdump is to convert ABCD into 41 42 43 44. An example of reverse hexdump is to... (3 Replies)
Discussion started by: LessNux
3 Replies

5. Solaris

Puzzled over over the relationship between the partition and geometry of hard disk.

Not sure why solaris couldn't detect the geometry of a hard disk which has a working OS of winxp pro. Is it due to the different OS that the partition information is stored in different location? When I type '"format" it is shown as below, c3d1 < drive type unknown>... (5 Replies)
Discussion started by: just.srad
5 Replies

6. Solaris

puzzled with VxVM and iostat..

Hi all, One disk on my root disk group failed in Veritas Volume manager. I replaced it with new one, initialized it and placed it with removed one. it Synchronized plexes and everything is fine. this node was second standby node of Sun cluster. yesterday I had failure on active node with boot... (1 Reply)
Discussion started by: samar
1 Replies

7. Programming

C++ Puzzled !!

#include <iostream.h> class A { public: void f(void) { cout << "hello world \n" ; } }; void main() { A *a; a = 0 ; a->f(); // OOPs...Am I mad? What am I going to do ? } (1 Reply)
Discussion started by: RipClaw
1 Replies

8. Programming

Puzzled with user ID.

I hava been reading AUPE these days. I really am puzzled with the presentation of real user(group) ID, effective user(group) ID. How do they effect on the execution of process? What's the relationship between them? Appreciate your help. (4 Replies)
Discussion started by: lethefe
4 Replies
Login or Register to Ask a Question