How to see what /bin/sh points to
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/shstat -L -c %i /bin/bash
Since you are only searching through bin
anyway, you can bypass find
entirely and just check if sh
and bash
are hard links to the same file:
test /bin/sh -ef /bin/bash
OR
[ /bin/sh -ef /bin/bash ]
This is not as reliable as running find
on all the possibilities, but it's a good start. While AIX find
doesn't support -samefile
, it does support -exec
, which can be combined with the command above to simulate the same functionality:
find -L /bin -exec test /bin/sh -ef '{}' ';'
Check for GNU Bash
I'm going to answer your question in a different way, because it's actually simpler to find out if sh is GNU Bash (or something else that responds to a --version
flag) than it is to chase inodes. There's also the edge case where the shell is renamed rather than linked, in which case mapping links won't really help you find an answer.
For example, to interrogate /bin/sh on macOS:
$ /bin/sh --versionGNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)Copyright (C) 2007 Free Software Foundation, Inc.
Alternatively, you can grep (or similar) for the string bash
to capture the exit status. For example:
# Close stderr in case sh doesn't have a version flag.if sh --version 2>&- | grep -qF bash; then echo "sh is bash"else echo "sh isn't bash"fi
Of course, /bin/sh could be some other shell besides bash or the original bourne shell, but that's outside the scope of your original question. However, many shells such as ksh and tcsh also support the version flag, so judicious use of a case
statement could help you extend the test to determine exactly which shell binary /bin/sh really is.