(Fwd) Re:Bash Programming

Lennart Sorensen lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Fri Aug 20 14:15:37 UTC 2004


On Fri, Aug 20, 2004 at 09:54:42AM -0400, Tim Writer wrote:
> This assumes /bin/sh is the first instance of sh in your PATH which is
> usually but not always the case.  If your PATH was:
> 
>     /usr/local/bin:/bin:/usr/bin
> 
> and /usr/local/bin/sh exists and is executable, "sh script.sh" would be
> equivalent to running "/usr/local/bin/sh script.sh".

Yeah of course.  Assuming /bin/sh is bash is not safe.  On Debian policy
states /bin/sh can be any posix compliant shell (ash, dassh, bash, etc).
There are occationally bugs found where someone used bashisms in a file
that was supposed to be a shell script and work with any posix shell.

> Only if the script doesn't begin with "#!".  IOW, the default behaviour (of
> running the script with /bin/sh) is only activated if the script doesn't
> already specify an interpreter via a "#!" first line.  For example, if the
> first line of the script was:

I didn't think there was a default behaviour.  Either a file is a known
binary file format which the sytem knows how to execute (and there are
ways to register more with the misc bin format system so you could say,
run java applets by just typing their name and having it launch in a
jvm).  If it is NOT a binary format that is known, it checks for a #!
line and does whatever it says with that file as argument in that case.

>     #!/bin/cat
> 
> running "./script.sh" is equivalent to:
> 
>     /bin/cat ./script.sh

Hmm, self displaying files that must start with a specific line.  Not
sure that's so useful :)  How about /usr/bin/less.  Self paging files.

Lennart Sorensen
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list