Loading...

How to escape single quote characters in bash command substitution

Answer #1 100 %

Change this line:

SQOOP_COMMAND="SQOOP statement : sqoop import blah blah "$CUSTOM_PARAMS""

To this:

SQOOP_COMMAND="SQOOP statement : sqoop import blah blah $CUSTOM_PARAMS"

Also change this line:

echo $SQOOP_COMMAND

To this:

echo "$SQOOP_COMMAND"

Or if you want to embed the extra double-quotes, then to this:

SQOOP_COMMAND="SQOOP statement : sqoop import blah blah \"$CUSTOM_PARAMS\""

What's happening is that the way you wrote it, the first embedded double-quote closes the quoted expression. Effectively you have there SQOOP statement : sqoop import blah blah quoted, followed by $CUSTOM_PARAMS unquoted, followed by an empty string (""). If you want to embed double-quotes within double-quotes, then you need to escape them with \.

But it seems to me you don't want to embed double-quotes at all.

You’ll also like:


© 2022 CodeForDev.com -