Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see what /bin/sh points to

Tags:

bash

shell

unix

aix

I was reading about the differences between /bin/sh and /bin/bash and came across this interesting question/answer: here

I made a comment to the answer asking this same question in my title to which he replied with an updated answer:

How can you find out what /bin/sh points to on your system?

The complication is that /bin/sh could be a symbolic link or a hard link. If it's a symbolic link, a portable way to resolve it is:

> % file -h /bin/sh
> /bin/sh: symbolic link to bash 

If it's a hard link, try

> % find -L /bin -samefile /bin/sh 
> /bin/sh 
> /bin/bash

I tried this and had trouble so I thought I would make a separate question.

My results from the linked answer:

>file -h /bin/sh
>/bin/sh: executable (RISC System/6000) or object module

>find -L /bin -samefile /bin/sh
>find: bad option -samefile

What am I missing? I'm running AIX:

>oslevel -s
7100-03-03-1415
like image 525
exit_1 Avatar asked Apr 20 '17 20:04

exit_1


People also ask

What is this #!/ Bin sh?

#!/bin/sh: It is used to execute the file using sh, which is a Bourne shell, or a compatible shell. #!/bin/csh: It is used to execute the file using csh, the C shell, or a compatible shell.

Why does #!/ Bin Sh have to be the first line of my scripts?

Adding #!/bin/bash as the first line of your script, tells the OS to invoke the specified shell to execute the commands that follow in the script. #! is often referred to as a “hash-bang”, “she-bang” or “sha-bang”. Though it is only executed if you run your script as an executable.

How do I change my bin sh?

Answer: The chsh command changes the login shell of your username. When altering a login shell, the chsh command displays the current login shell and then prompts for the new one. Here are the most common shells, which are listed in /etc/shells: /bin/sh.


1 Answers

If you need to programatically test if they are the same, you can use stat to query the inode of /bin/sh and compare with the inode of /bin/bash.

if [ $(stat -L -c %i /bin/sh) -eq $(stat -L -c %i /bin/bash) ]; then
    .....
fi

If you just need to see with your eyes if they are the same run the stat commands and see if they return the same inode number.

stat -L -c %i /bin/sh
stat -L -c %i /bin/bash
like image 64
alvits Avatar answered Sep 24 '22 14:09

alvits