What's wrong

What's wrong

Post by Gareth Youn » Thu, 27 Jan 2000 04:00:00



Dear all

I'm not able to get the correct result form the following script

###########
#!/bin/sh
procs='ps -ef'
head='echo "$procs" | line'
echo "$head"
#############

Please advise
Best Regards

GY.

 
 
 

What's wrong

Post by Ralf Draege » Thu, 27 Jan 2000 04:00:00



> Dear all

> I'm not able to get the correct result form the following script

> ###########
> #!/bin/sh
> procs='ps -ef'
> head='echo "$procs" | line'
> echo "$head"
> #############

> Please advise
> Best Regards

> GY.

You meant youll get
Quote:> echo "$head"

echo "$procs" | line

Obviously youre yousing the wrong quote "'" is used to escape a string
from shellexpantion, not really, what you intended to do.
Use "`" instead and itll work.

Or even better use $( command ) instead because it also allows nesting
commands.

HTH, Ralf.
--

- Intraplan Consult Gmbh     Orleansplatz 5a  81667 Muenchen   +49 89 45911-0 -

... you start off with a typical message, let's say a 2.5MB Word document
containing three lines of text and a macro virus ...           -- Peter Gutmann

 
 
 

What's wrong

Post by Eric Youngquis » Thu, 27 Jan 2000 04:00:00


Gareth,

    You need to use the backticks, "`", instead of the forward ticks, "'",
to execute the commands.

#!/bin/sh
procs=`ps -ef`
head=`echo $procs | line`
echo $head

Thanks,
Eric


Quote:> Dear all

> I'm not able to get the correct result form the following script

> ###########
> #!/bin/sh
> procs='ps -ef'
> head='echo "$procs" | line'
> echo "$head"
> #############

> Please advise
> Best Regards

> GY.

 
 
 

What's wrong

Post by Christopher J. Matter » Thu, 27 Jan 2000 04:00:00



> Dear all
> I'm not able to get the correct result form the following script
> ###########
> #!/bin/sh
> procs='ps -ef'
> head='echo "$procs" | line'
> echo "$head"
> #############
> Please advise
> Best Regards
> GY.

Main problem is you're using the wrong quotes.  Backticks,
not single quotes:

`ps -ef` not 'ps -ef'; `echo "$procs" | line` not 'echo "$procs" | line'

                            Chris Mattern

 
 
 

What's wrong

Post by Christopher J. Matter » Thu, 27 Jan 2000 04:00:00



> Or even better use $( command ) instead because it also allows nesting
> commands.

Not unless /bin/sh is an alias for ksh or bash on his system.  If it's
a true Bourne shell, $() won't work

                            Chris Mattern

 
 
 

What's wrong

Post by Alexander Avtansk » Fri, 28 Jan 2000 04:00:00



> Dear all

> I'm not able to get the correct result form the following script

> ###########
> #!/bin/sh
> procs='ps -ef'
> head='echo "$procs" | line'
> echo "$head"
> #############

> Please advise
> Best Regards

> GY.

Use backquotes (`) instead of single quotes (').

- Alex