LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bin/bash and bin/sh (https://www.linuxquestions.org/questions/linux-newbie-8/bin-bash-and-bin-sh-4175490536/)

srini1304 01-08-2014 04:59 AM

bin/bash and bin/sh
 
hai
what is the difference between bin/bash and bin/sh

TenTenths 01-08-2014 05:22 AM

bin/sh was the old "original" shell, it's left for nostalgic compatibility but is usually symlinked to bin/bash unless the sysadmin has another shell preference.

laz000 01-08-2014 06:28 AM

TenTenths is correct regarding the symlinking of sh to bash. My understanding is that when you put #/bin/sh at the top your your scripts though, bash will operate in Bourne Shell and perhaps lose some Bash features as stated in The Linux Documentation Project's Advanced Shell Scripting guide:

"Using #!/bin/sh, the default Bourne shell in most commercial variants of UNIX, makes the script portable to non-Linux machines, though you sacrifice Bash-specific features. The script will, however, conform to the POSIX [5] sh standard."

http://tldp.org/LDP/abs/html/sha-bang.html

druuna 01-08-2014 06:47 AM

This from the bash manual page:
Code:

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.  When invoked as an  interac‐
      tive  login  shell, or a non-interactive shell with the --login option,
      it first attempts to read and execute commands  from  /etc/profile  and
      ~/.profile,  in  that  order.  The  --noprofile  option may be used to
      inhibit this behavior.  When invoked as an interactive shell  with  the
      name  sh,  bash  looks for the variable ENV, expands its value if it is
      defined, and uses the expanded value as the name of a file to read  and
      execute.  Since a shell invoked as sh does not attempt to read and exe‐
      cute commands from any other startup files, the --rcfile option has  no
      effect.  A  non-interactive  shell  invoked  with the name sh does not
      attempt to read any other startup files.  When  invoked  as  sh,  bash
      enters posix mode after the startup files are read.



All times are GMT -5. The time now is 08:32 AM.