(Fwd) Re:Bash Programming

Tim Writer tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org
Fri Aug 20 13:54:42 UTC 2004


"Paul King" <pking123-rieW9WUcm8FFJ04o6PK0Fg at public.gmane.org> writes:

> From:           	Paul King <pking123-rieW9WUcm8FFJ04o6PK0Fg at public.gmane.org>
> Subject:        	Re: [TLUG]: Bash Programming
> To:             	Devin Whalen <devin-Gq53QDLGkWIleAitJ8REmdBPR1lH4CV8 at public.gmane.org>
> Send reply to:  	pking123-rieW9WUcm8FFJ04o6PK0Fg at public.gmane.org
> Date sent:      	Wed, 18 Aug 2004 21:15:19 -0400
> 
> > > Bash-2.05b supports array, as evidenced by Linux box.  Your scripts runs
> > > okey here on 2.05b and 3.0.
> > 
> > Ok...I ran it with ./file.sh and it worked fine!!  What is the
> > difference between ./ and sh?  I don't want to make the same mistake
> > again.
> 
> sh script.sh
> runs the script as though the line 
>    #! /bin/sh
> were inserted at the beginning of the script.

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".

> ./script.sh
> runs the script as if it has execute privelages and the line
>    #! /bin/sh
> is inserted at the beginning of the script. In fact, script.sh should have
> execute privelages if it to be run this way.

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:

    #!/bin/cat

running "./script.sh" is equivalent to:

    /bin/cat ./script.sh

-- 
tim writer <tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org>                                  starnix inc.
905.771.0017 ext. 225                           thornhill, ontario, canada
http://www.starnix.com              professional linux services & products
--
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