[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash

On Wed, Dec 18, 2002 at 04:01:51AM +0000, Pigeon wrote:
> How does that one work then?


$ echo '#!/bin/bash' > foo.sh
$ echo 'echo "It runs"' >> foo.sh
$ cat foo.sh 
echo "It runs"
$ ./foo.sh
bash: ./foo.sh: /bin/bash: bad interpreter: Permission denied
$ bash foo.sh 
It runs

You can run a non-executable script by passing its filename to the
proper interpreter (in which case the #! line isn't needed, BTW).

As mentioned earlier, though, the profile is sourced, not executed.
The difference?

$ echo 'export BAR=1' > foo.sh
$ chmod +x foo.sh
$ ./foo.sh
$ echo $BAR

$ source foo.sh
$ echo $BAR

Executing foo.sh started a new shell process and set BAR in that process,
but had no effect on the shell I gave the command to.  Sourcing it
caused it to run in the existing shell, so it was able to modify that
environment.  I'm sure you can see that profiles would be much less
useful if they were executed instead of sourced...

The freedoms that we enjoy presently are the most important victories of the
White Hats over the past several millennia, and it is vitally important that
we don't give them up now, only because we are frightened.
  - Eolake Stobblehouse (http://stobblehouse.com/text/battle.html)

Reply to: