Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does the sh linux command use the users current shell, even if its not bash? For example, let's say the user bob is running csh. If I create a script with functions and csh and try and execute it with:

sh cshtestscript

Will this run with csh?

Then assume another use joe is using bash. If I create another script with functions and bash script and try and execute it with:

sh bashtestscript

Will this run with bash?

share|improve this question
up vote 4 down vote accepted

sh is just a standard executable, which is always a specific shell. There is no magic to detect which shell to use.

% whereis sh
sh: /bin/sh
% ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Mar 29 11:53 /bin/sh -> dash

On Ubuntu systems, /bin/sh is (by default) a symlink to dash, which is a minimal POSIX shell intended for non-interative use. If you run sh cshtestscript on an Ubuntu system, it will try to run the script with dash.

The correct way to handle this is to add a shebang to the script which indicates which shell to use, make the script executable, and always execute it as ./cshtestscript.

share|improve this answer
Yeah, basically I am looking for a way to run these scripts without actually creating files. So something like: sh echo "#!/bin/bash free -m". Would that work? – Justin Jun 21 '12 at 6:49
@Justin Just use bash -c 'free -m' – mgorven Jun 21 '12 at 7:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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