This command
echo "mysql -u root nextcloud -Bse 'DELETE FROM oc_filecache WHERE path=""${FILE_PATH}"";'"
will show that
mysql -u root nextcloud -Bse 'DELETE FROM oc_filecache WHERE path="files_encryption/keys/files/xxx/xxxx/xxx L'AME/2xxxx/OC_DEFAULT_MODULE/master_x626.shareKey";'
There is a single quote in the path. When i execute command, this does not work. When script execute this commande
mysql -u root nextcloud -Bse 'DELETE FROM oc_filecache WHERE path="${FILE_PATH}";'
It does not work too. Row is not deleted.
From HeidySQL this command work, row is deleted.
DELETE FROM oc_filecache WHERE path="files_encryption/keys/files/xxx/xxxx/xxx L'AME/2xxxx/OC_DEFAULT_MODULE/master_x626.shareKey";
What should i do to escape single quote from variable throught mysql -Bse? Thanks.
2
Answers
Try this :
The first
'
close the command,'
escape single quote out of the whole query, and the last ‘ concats the rest of the command.Your problem isn’t the single quote in the string stored in the variable, it’s that you’re single-quoting the whole string that includes that variable so the shell can’t expand it. Instead of:
try:
or similar and if that’s not all you need, try something else where
$FILE_PATH
isn’t inside a string delimited by single quotes.