In Shell script, How can I check if /bin/sh
is softlink'ed to dash
or bash
, I may have /bin/sh -> dash
or /bin/sh -> bash
Asked
Active
Viewed 1,074 times
1

rodee
- 3,233
- 5
- 34
- 70
-
In general, btw, even if `/bin/sh` is linked to bash, your code should work as if it were linked to dash anyhow. Bash doesn't promise to provide anything more than minimum POSIX sh functionality when invoked under the `sh` name [though in practice it does, to an extent that varies across releases], so any script using a `#!/bin/sh` shebang should be written to function properly with that functionality alone. – Charles Duffy May 24 '16 at 20:32
-
Thanks Charles, yes its a duplicate, sorry, the other answer helped me. – rodee May 24 '16 at 20:41
-
http://stackoverflow.com/questions/31596363/how-to-recursively-resolve-symlinks-without-readlink-or-realpath/31597888#31597888, btw, is also relevant to being able to what `readlink` does without actually *having* `readlink` (includes various fallback implementations, including GNU `find`, `perl`, or even ultimately `ls -l`). – Charles Duffy May 24 '16 at 21:04
1 Answers
2
You can use this command to print the filename your symlink is pointing to:
readlink -f $(command -v sh)
or using stat
command:
stat -c '%N' $(command -v sh)

anubhava
- 761,203
- 64
- 569
- 643
-
1`which` over `command -v`? (The latter is actually mandated by current POSIX; the former is just... frequently available, AFAIK). – Charles Duffy May 24 '16 at 20:53
-
-
1...hmm. I wonder if I should add `stat -c` to http://stackoverflow.com/questions/31596363/how-to-recursively-resolve-symlinks-without-readlink-or-realpath/31597888#31597888. OTOH, any platform with GNU stat will presumably also have GNU find, and thus be already covered. – Charles Duffy May 24 '16 at 21:08
-