Hi,
I'm writing a KSH script, and at one point, I have to call a new shell and perform some variable assignments.
I noticed that the assignment is not working.
Please see two samples below:
Command 1:
#>ksh "i=2;echo I is $i"
Output:
#>I is
Command 2:
#>ksh <<EOF
> i=2
> echo I is $i
> EOF
Output:
#>I is
I tried, using export, typeset, set, and none of them seem to work.
Your internal ksh command is being constructing by an external ksh instance. ksh looks inside double quotes and replaces variables. Since i was not set, $i is replaced with nothing which is what your internal ksh will see.
I understand that the parent shell would try to replace $i with the value of i (which is NULL, and hence the output).
#>ksh <<EOF
> i=2
> echo I is $i
> EOF
#> I is
So, how would be supress the parent shell, and let the new KSH to replace the value (of 2) ?
Awesome, it works. That was a new thing I learned. Thanks a lot.
Lastly, would you know a good site where I could find some reading material on such things? I tried searching the web. Not sure, if it was my inappropriate search string, or lack of topics, I did not find any.
However, I always recommend reading the shells' documentation. Chet Ramey and co have a really instructive bash reference manual, from which you will learn all sorts of intracacies about both bash and all Bourne-shell derivatives: http://cnswww.cns.cwru.edu/~chet/bash/bashref.html
Read it closely, several times, and come back to it whenever you need. It is muc more readable than man pages for in-depth understadning. If documents bash clearly, but sometimes the functionality of other sheels differ. But I found that after reading this, I could easilly understand the man pages of other shells and understand how those shells differ.