0

I am running an Ubuntu distro where /bin/sh is a symlink to /bin/dash. While this is OK for most of my users, one of them must have bin/sh "symlinked" to /bin/bash.

Is that possible? I am not sure how to do this.

Regards.

3

[…] one of them must have /bin/sh symlinked to /bin/bash.

I suspect that the actual state of affairs is:

[…] one of them has some badly written shell scripts with Bashisms in, and doesn't want to fix xyr bad scripts.

You cannot do a per-user symbolic link, obviously. So get your user to get those Bashisms out of any shell script that uses /bin/sh as its interpreter, and to put /bin/bash (or the alternatives mentioned by piernov) in any shell scripts where the Bourne Again shell really is supposed to be the script interpreter.

These scripts, if they assume that sh is only ever the Bourne Again shell or if they rely upon Bashisms and don't in fact invoke the Bourne Again shell as bash (Even invoking it as sh is wrong if one wants some of a fair number number of Bashisms.), are broken and should be mended.

Further reading

2

/bin/sh is just a Bourne shell. Both dash and bash can act as sh-compatible shells, and since original Bourne shell isn't used anymore, sh is often a symlink to bash or dash (mainly on Ubuntu), or even zsh.

When using sh though, you shouldn't be using any specificity of a particular shell. That's why a script with a #!/bin/sh shebang shouldn't rely on any bashism for example. When it is using any particularity of bash, it should be using #!/usr/bin/env bash. That is for a shell used to run scripts.

Another aspect of shell is the command prompt used by an user. Most of the time it is defined in /etc/passwd, and the choice is at the discretion of the distribution you're using. If the default is to use dash, you can obviously change the line in /etc/passwd for a specific user and put /usr/bin/bash.

Finally, even if it's not a good idea, if you really want the sh command to run bash, if it's in a shell you should be able to alias it, or create a symlink to it in another directory (~/bin for example) then prepend it to the PATH (export PATH="~/bin:${PATH}").

  • More accurately, /bin/sh is usually not the Bourne shell itself, but a link to another shell which adheres to the POSIX specification, which itself is based on but not identical to the original Bourne shell. – chepner Mar 11 '14 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.