unix - How to escape single quote characters in bash command substitution -


i want generate sqoop command appended variable custom_params. have defined variable in file : hi.cfg

the variable have single quotes 'orc'.

cat hi.cfg custom_params="--query select * blah..blah \$conditions --split-by blah --create-hcatalog-table --hcatalog-external-table --hcatalog-storage-stanza stored 'orc' --compress --compression-codec 'snappy' --fields-terminated-by '|' -m 5 --target-dir /any/dir" 

when source file on command prompt , echo gives me whats written on there looks correct.

source hi.cfg echo "$custom_params" --query select * blah..blah $conditions --split-by blah --create-hcatalog-table --hcatalog-external-table --hcatalog-storage-stanza stored 'orc' --compress --compression-codec 'snappy' --fields-terminated-by '|' -m 5 --target-dir /any/dir 

but when call shell script below :

cat hi.sh  echo "generating sqoop command" source $home/hi.cfg echo "${custom_params}" sqoop_command="sqoop statement : sqoop import blah blah "$custom_params"" echo $sqoop_command 

the * character in variable been treated command:

sh hi.sh  generating sqoop command --query select * blah..blah $conditions --split-by blah --create-hcatalog-table --hcatalog-external-table --hcatalog-storage-stanza stored 'orc' --compress --compression-codec 'snappy' --fields-terminated-by '|' -m 5 --target-dir /any/dir sqoop statement : sqoop import blah blah --query select 0 00 000000_0 000073_0 000103_0 02 09.txt 1  blah..blah $conditions --split-by blah --create-hcatalog-table --hcatalog-external-table --hcatalog-storage-stanza stored 'orc' --compress --compression-codec 'snappy' --fields-terminated-by '|' -m 5 --target-dir /any/dir 

i need run sqoop statement later on in script , have tried couple of options didn't help. tried \* didn't help, outputs:

generating sqoop command --query select \* blah..blah $conditions --split-by blah --create-hcatalog-table --hcatalog-external-table --hcatalog-storage-stanza stored 'orc' --compress --compression-codec 'snappy' --fields-terminated-by '|' -m 5 --target-dir /any/dir sqoop statement : sqoop import blah blah --query select \* blah..blah $conditions --split-by blah --create-hcatalog-table --hcatalog-external-table --hcatalog-storage-stanza stored 'orc' --compress --compression-codec 'snappy' --fields-terminated-by '|' -m 5 --target-dir /any/dir` 

change 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 line:

echo $sqoop_command 

to this:

echo "$sqoop_command" 

or if want embed double-quotes, this:

sqoop_command="sqoop statement : sqoop import blah blah \"$custom_params\"" 

what's happening way wrote it, first embedded double-quote closes quoted expression. have there sqoop statement : sqoop import blah blah quoted, followed $custom_params unquoted, followed empty string (""). if want embed double-quotes within double-quotes, need escape them \.

but seems me don't want embed double-quotes @ all.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -