LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-10-2009, 03:24 PM   #1
jonette20
Member
 
Registered: Jul 2007
Location: Ohio
Distribution: Ubuntu 7.04
Posts: 65

Rep: Reputation: 15
bin/sh & bin/bash


Hi,

I noticed on my system that some scripts have bin/sh and others bin/bash.
Does this make a difference?
I have Ubuntu 8.04 installed.

Thanks
 
Old 08-10-2009, 03:39 PM   #2
joeBuffer
Member
 
Registered: Jul 2009
Distribution: Ubuntu 9.04
Posts: 328

Rep: Reputation: 42
/bin/sh is usually (always, as far as I know ... but I could be wrong) a link to another file. Using Slackware, I know it is a link to /bin/bash, using Ubuntu 9.04 it is a link to /bin/dash (the Debian Almquist shell).
Code:
joebuffer@ubuntu:~$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 2009-08-07 17:32 /bin/sh -> dash
 
Old 08-10-2009, 04:44 PM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
"sh" is the name of the original Bourne Shell. Nowadays, most shells try to be backwards compatible with it, so, at least theoretically, most actual shells should be able to run an old script written for "sh" without needing any modification at all. "sh" is old and not too featureful, so nowadays linux distros use anything else (bash is very famous, but other common ones are ksh, csh, zsh, dash, ash...).

/bin/sh is usually a symlink to any of these (I am not sure all of them could comply, particularly csh), so if in your system /bin/sh is a symlink to /bin/bash, there's no difference in using either of them. However, if you aim for the widest portability, you want to use #!/bin/sh in your scripts. Of course, that means that you then shouldn't use any bash-only feature (bash is a lot more complete than the original sh). All the unix alikes will always have a substitute for sh, but not all of them will always have bash installed, or any other shell by that matter.

That's why the #!/bin/sh bang is still used, and will continue to be so.

Last edited by i92guboj; 08-10-2009 at 04:48 PM.
 
Old 08-10-2009, 05:07 PM   #4
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
Quote:
Originally Posted by i92guboj View Post
if in your system /bin/sh is a symlink to /bin/bash, there's no difference in using either of them.
Well, not quite. Although /bin/sh is a symlink to /bin/bash, when bash is called as /bin/sh, its behavior is somewhat different than when it's invoked as /bin/bash. It's right there in man bash:
Quote:
If bash is invoked with the name sh, it tries to mimic the startup
behavior of historical versions of sh as closely as possible, while
conforming to the POSIX standard as well.
But otherwise you're correct, /bin/sh is added for backward compatibility and maximum portability.
 
Old 08-10-2009, 05:17 PM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
You are quite right, in my aim to simplify the issue I omitted info so that part of my post wasn't totally correct. However, even when invoked that way, all the bashishms will still work, you can try this one which contains bash specific code that would fail to run on the genuine bourne sh

Code:
#!/bin/sh
foo="bar"
echo "${foo/r/ll}"
 
Old 08-10-2009, 05:32 PM   #6
joeBuffer
Member
 
Registered: Jul 2009
Distribution: Ubuntu 9.04
Posts: 328

Rep: Reputation: 42
I've read this was true, also, but thought saying it was a link or symlink would be easier, and I haven't really read about the details of using sh instead of bash and what differences it makes. I do remember reading that it becomes POSIX, but not fully from what I remember.

Last edited by joeBuffer; 08-10-2009 at 05:33 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Really strange problem - RedHat /bin/sh vs /bin/bash leeharris Programming 4 02-13-2009 06:35 AM
Difference between /bin/bash & /bin/sh paragkalra Programming 11 01-02-2009 06:10 AM
How to add paths to sbin, bin/bash, bin sh for users gopi.d Fedora 3 12-07-2007 12:47 AM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM
bin/bash:usr/bin/lpr NO SUCH FILE OR DIRECTORY Adibe_Hamm Linux - Newbie 3 10-14-2003 02:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration