Strange error.. help

Hi,

When I give the following
$ ps -ef | grep `echo $var1` | grep -v "grep `echo $var1`" | awk '{print $3}' | grep -v `echo $var1

80892

But when I give the following (made as command substitution) , I get error
$var2=`ps -ef | grep `echo $var1` | grep -v "grep `echo $var1`" | awk '{print $3}' | grep -v `echo $var1``

ksh: 0403-057 Syntax error: `|' is not expected.

Similarly , when I give the following
$ps -ef | grep `echo $var2` | grep -v "echo $var1" | grep -e "-ksh" | wc -l

1

But when I give the following (made as command substitution) , I get error
echo `ps -ef | grep `echo $var2` | grep -v "echo $var1" | grep -e "-ksh" | wc -l`

Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] -e pattern_list...
[-f pattern_file...] [file...]
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] [-e pattern_list...]
-f pattern_file... [file...]
Usage: grep [-E|-F] [-c|-l|-q] [-insvxbhwy] [-p[parasep]] pattern_list [file...]
ksh: 0403-057 Syntax error: `|' is not expected.

Where am i going wrong...
Pls help...
Thanks

You know that you're trying to get the backticks to nest, but the shell doesn't. It sees the command as:

var2=`ps -ef | grep `echo $var1` | grep -v "grep `echo $var1`" | awk '{print $3}' | grep -v `echo $var1``
     |______________|          |_________________|          |_______________________________|          ||
          1                           2                                    3                            4

The korn shell introduced a new syntax to deal with this. Instead of
`echo $var`
do
$(echo $var)

But why do `echo $var` at all? In most cases, you can just use $var.

And I just deleted your 2nd thread. Please don't do that...it's against the rules. We have a link to the rules at the bottom of every page.