I went through a shell scripting tutorial explaining about global variables (export
).
I encountered a do-it-yourself example to illustrate the concept of global variables in shell scripting, and I tried it by:
$ cat trial
vech=Bus
echo $vech
/bin/bash
echo "before empty line"
echo $vech
echo "after empty line"
vech=Car
echo $vech
exit
echo $vech
The expected output for this program was:
Bus
before empty line
after empty line
Car
Bus
But I got :
$ chmod 777 trial
$ ./trial
Bus
$
where I am getting wrong?, I am new this flavor please help me.
echo
and everything up to theexit
are meant to be commands to/bin/bash
./bin/bash
does not receive the lines after it as input. You could replace it withsleep 1
and the script would not be much different (except now you have to explicitly exit from Bash before the script will continue).