Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have tried many things, but I'm new to the shell. Is it possible to have both double and single quotes within an echo?

I want to generate echo "scan 'LPV',{FILTER => "(PrefixFilter ('MP1-Eq1')"}" for system call, but I am getting an error because of the mutiple double and single quotes.

ftable="echo" " \"" "scan" " " "'LPV',{FILTER => " "\"" "\(" "PrefixFilter ""\(""'MP1-Eq1'" "\)" "\"" "\}" "\" "    
echo "scan 'LPV',{FILTER => "(PrefixFilter ('MP1-Eq1')"}"
bash: syntax error near unexpected token `('

How can I write scan 'LPV',{FILTER => "(PrefixFilter ('MP1-Eq1')"}? The syntax is hbase's and I can't change it...

EDIT

I want to call echo within system call.

ftable="echo "scan 'LPV',{FILTER => "(PrefixFilter ('MP1-Eq1')"}" "
system(ftable)
error

I have tried with $ but

ftable="echo $'scan" "\'" "LPV" "\'" ",{FILTER => " "\"" "(PrefixFilter (" "\'" "MP1-Eq1" "\'" ")" "\"" "}' '"
system(ftable)
error

Getting an error because of double quote.

share|improve this question
    
What language is this system()? –  glenn jackman Jun 2 at 10:13
    
basically i m calling within my awk script. –  Aashu Jun 2 at 10:19

2 Answers 2

up vote 5 down vote accepted

In bash:

echo $'scan \'LPV\',{FILTER => "(PrefixFilter (\'MP1-Eq1\')"}'

or

echo "scan 'LPV',{FILTER => \"(PrefixFilter ('MP1-Eq1')\"}'"

For longer strings this may be a more convinient alternative:

> cat <<EOT
scan 'LPV',{FILTER => "(PrefixFilter ('MP1-Eq1')"}
EOT

with EOT or \EOT, depending on whether parameter expansion and quote removal (backslash) are intended or not.

Usage within awk

Defining this string within awk would make everything even more complex. This should be done outside awk in the shell:

ftable=$'echo "scan \'LPV\',{FILTER => "(PrefixFilter (\'MP1-Eq1\')"}"'
# echo "$ftable"
awk -v ftable="$ftable" '... system(ftable); ...'
share|improve this answer
    
@huake i am unable to call this from system. –  Aashu Jun 2 at 9:24
    
@Aashu I'm afraid I don't understand this remark. –  Hauke Laging Jun 2 at 14:32
    
actually i have some prameter which i am reading from file in awk and want to pass within this string,which i want to run on system(ftable). –  Aashu Jun 2 at 14:34
    
@Aashu It seems to me that awk wasn't mentioned before... However, I have extended my answer. –  Hauke Laging Jun 2 at 14:48

You just have to escape double quote inside double quote:

$ ftable="echo \"scan 'LPV',{FILTER => \"(PrefixFilter ('MP1-Eq1')\"}\""
$ echo $ftable
echo "scan 'LPV',{FILTER => "(PrefixFilter ('MP1-Eq1')"}"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.