variable assignment in new shell

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.

Could anyone tell me what I'm doing wrong?

Thanks in advance,
Maverick80

Use single quotes:
ksh 'i=2;echo I is $i'

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.

Thank you for your answer. I was over looking that aspect. Single quotes fixed the 1st issue.

However, is how would I get it correct, when I'm using a here document?
I.e; in the case below:
Command2:
#>ksh <<EOF
> i=2
> echo I is $i
> EOF

Output:
#>I is

Any ideas?

Thanks again,
Maverick80

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) ?

Thanks

Use:
ksh <<'EOF'

Change that one line only.

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.

Thanks again.
Regards,
Maverick80

The only sites I know are in the tutorial article in our FAQ section.

Here is a pretty good thread if you are interestsed in he syntax of here documents and how the shell treats things in a here doc: http://www.unix.com/showthread.php?p=80897\#post80897

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.