GOTCHA in Ubuntu - broken shell

Bill McGonigle bill at bfccomputing.com
Mon Oct 1 14:23:13 EDT 2007


On Oct 1, 2007, at 10:30, Tom Buskey wrote:

> What I'm saying is #!/bin/sh should run like #!/bin/sh.  export  
> VAR=value
> doesn't work in bourne shell.  So if you put that in a bourne shell  
> script
> with #!/bin/sh, then it should fail

That seems to be the root cause of the problem, IMHO.  Bash is  
_supposed to_ run in POSIX/Bourne-shell mode when invoked as /bin/sh,  
right?

It seems that lots of people are running #!/bin/sh and getting bash  
extensions to evaluate.  If this didn't happen none of this would be  
an issue, the scripts would never have left the barn.  The man page  
says:

        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.

What am I missing?

-Bill
-----
Bill McGonigle, Owner           Work: 603.448.4440
BFC Computing, LLC              Home: 603.448.1668
bill at bfccomputing.com           Cell: 603.252.2606
http://www.bfccomputing.com/    Page: 603.442.1833
Blog: http://blog.bfccomputing.com/
VCard: http://bfccomputing.com/vcard/bill.vcf



More information about the gnhlug-discuss mailing list