tags:

views:

274

answers:

4

Hi all,

#/!bin/sh

   if [ "`echo $desc $status | awk -F"," '{print $3}' | awk -F" " '{print $1}' | sed '/^$/d'`" != "OK" ]; then
        echo "howdy dody"
   fi

echo $desc $status | awk -F"," '{print $3}' | awk -F" " '{print $1}' | sed '/^$/d'

First if-condition won't run, im guessing it's because of improper quotation, but i can't figure it out.

Thanks in advance for any help.

A: 

If you're using Bash, I'd recommend $(...) instead of back-quotes. What error messages do you get? My guess is that the -F"," option to awk is not being quoted properly. Trying inserting \ to escape the quotation marks.

JesperE
Sorry, can't use $(...) very very old shell. MMm, good suggestion, gonna try that.
Anders
can't use $()?? then why the bash tag?
ghostdog74
Changed the topic.
Anders
Was simply a matter of escaping. Thanks for the help.
Anders
Update the tags as well, please.
JesperE
Done, thanks for the help.
Anders
A: 

At first glance, you might want to try escaping some of the double quotes:

   if [ "`echo $desc $status | awk -F"," '{print $3}' | awk -F" " '{print $1}' | sed '/^$/d'`" != "OK" ]; then
        echo "howdy dody"
   fi

to

   if [ "`echo $desc $status | awk -F\",\" '{print $3}' | awk -F\" \" '{print $1}' | sed '/^$/d'`" != "OK" ]; then
        echo "howdy doody"
   fi
Adam Luchjenbroers
Thanks for the help.
Anders
A: 

You can also use single quotes around the argument to the -F option as you have around other arguments:

if [ "`echo $desc $status | awk -F',' '{print $3}' | awk -F' ' '{print $1}' | sed '/^$/d'`" != "OK" ]; then
Dennis Williamson
A: 

Escaping the double quotes is certainly a good idea, but it looks like the $3 and the $1 are intended to be interpreted by awk. They are being interpreted by your shell instead. You probably want to escape the '$'s. (It is possible that you have meaningful values for $1 and $3 in the shell, but not likely.)

William Pursell
No, they're in single quotes so they don't need escaping.
Dennis Williamson