11
1
Can anybody explain to me what the shell does in the two examples A) and B) below? It obviously behaves differently, but I can't find out why the output is different.
Example:
Let's have a script in our current directory named bla.sh
with only one command:
echo ${0##/*} hello
A)
Started as: ./bla.sh
gives: ./bla.sh hello
B)
Started as: . bla.sh
gives: -bash hello
Since I use this in a script, the second output (because of the "-" in front of the -bash) kills the command. Of course, a simple --
before the ${...}
helped, but I would love to understand what causes the output in the first place.
I love bash. And vi[m]. But I digress…
1
See also http://mywiki.wooledge.org/BashFAQ/060 for some examples. Note that
– mrucci – 2010-04-15T06:43:10.353source
is a bash alias for.
, not the contrary andsource
won't work in other shells.3Moreover, if you change bash environment in bla.sh, these changes are taken into account after . bla.sh but not after ./bla.sh. this is because . bla.sh runs in the context of the current bash whereas ./bla.sh runs as a subprocess. – mouviciel – 2009-09-15T12:09:51.943