skip to Main Content

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


  1. Try this :

    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";'
    

    The first ' close the command, ' escape single quote out of the whole query, and the last ‘ concats the rest of the command.

    Login or Signup to reply.
  2. 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:

    mysql ... 'DELETE FROM oc_filecache WHERE path="${FILE_PATH}";'
    

    try:

    mysql ... "DELETE FROM oc_filecache WHERE path="${FILE_PATH}";"
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search