I want to run a small bash script, but I'm getting extra junk added around quotes.
I thought that using a single quote mark '
would give me a literal string?
I used set +x
to see what the script is really doing.
The code is this:
set -x
task='mysql --port=3336 --host=127.0.0.1 -u root training_service -e "DELETE FROM expert_bundle_claim; " '
echo $task
$task
When I run I'll see:
▶ bin/run-local.sh
+ task='mysql --port=3336 --host=127.0.0.1 -u root training_service -e "DELETE FROM expert_bundle_claim; " '
+ echo mysql --port=3336 --host=127.0.0.1 -u root training_service -e '"DELETE' FROM 'expert_bundle_claim;' '"'
mysql --port=3336 --host=127.0.0.1 -u root training_service -e "DELETE FROM expert_bundle_claim; "
+ mysql --port=3336 --host=127.0.0.1 -u root training_service -e '"DELETE' FROM 'expert_bundle_claim;' '"'
mysql Ver 14.14 Distrib 5.6.47, for osx10.15 (x86_64) using EditLine wrapper
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
and then errors.
So basically the actual SQL command "DELETE FROM expert_bundle_claim; "
gets mangled to '"DELETE' FROM 'expert_bundle_claim;' '"'
.
I tried it the with the '
and "
inner/outer reversed, and it's even more mangled.
+ task='mysql --port=3336 --host=127.0.0.1 -u root training_service -e '\'' DELETE FROM expert_bundle_claim; '\'' '
+ mysql --port=3336 --host=127.0.0.1 -u root training_service -e ''\''' DELETE FROM 'expert_bundle_claim;' ''\'''
tried another way just piping into mysql with < filename.sql
but that gets interpolated to a quoted '<'
+ task='mysql --port=3336 --host=127.0.0.1 -u root training_service < ./bin/revert_tasks.sql'
+ mysql --port=3336 --host=127.0.0.1 -u root training_service '<' ./bin/revert_tasks.sql
Any suggestions how best to handle this and prevent interpolation?