Bash script with docker command not running when passing argument | Env: WSL2 with docker desktop
I am new to WSL + docker desktop on windows. normally this would not be an issue. but i have no clue what im doing wrong here. I have a script /usr/local/bin/mysqlcmd which takes a SQL query as arg and supposed to print it out after executing a docker exec
command.
#!/bin/bash
args="$1"
echo "Recieved $args"
sql_query="'mysql -u root -proot --database dev --batch -e "$args"'"
echo "SQL query: $sql_query"
docker exec -it hellomaven_db_1 bash -c 'mysql -u root -proot --database dev --batch -e "select * from location limit 10"'
echo "FAILURE"
docker exec -it hellomaven_db_1 bash -c "$sql_query"
and the output when i run mysqlcmd 'select * from location limit 4'
is
Recieved select * from location limit 10
SQL query: 'mysql -u root -proot --database dev --batch -e "select * from location limit 4"'
mysql: [Warning] Using a password on the command line interface can be insecure.
id lat lon datetime_ts datetime_id
1 -0.1997 -34.7696 2020-11-06 11:32:37 1604662359
2 -0.682 -34.4279 2020-11-06 11:32:47 1604662369
3 -1.1641 -34.0864 2020-11-06 11:32:57 1604662378
4 -1.6714 -33.7267 2020-11-06 11:33:06 1604662388
FAILURE
bash: mysql -u root -proot --database dev --batch -e "select * from location limit 10": command not found
failed to resize tty, using default size
%
what bugs me is the bash: mysql -u root -proot --database dev --batch -e "select * from location limit 10": command not found
. both the docker exec commands are identical. or i am missing something ?
Thanks in advance.
Source: Docker Questions