Escaping MYSQL command lines via Bash Scripting

后端 未结 8 943
走了就别回头了
走了就别回头了 2020-12-06 01:09

PHP has mysql_real_escape_string() to correctly escape any characters that might cause problems. What is the best way to mimic this functionality for BASH?

相关标签:
8条回答
  • 2020-12-06 01:49

    In Bash, printf can do the escaping for you:

    $ a=''\''"\;:#[]{}()|&^$@!?, .<>abc123'
    $ printf -v var "%q" "$a"
    $ echo "$var"
    \'\"\\\;:#\[\]\{\}\(\)\|\&\^\$@\!\?\,\ .\<\>abc123
    

    I'll leave it to you to decide if that's aggressive enough.

    0 讨论(0)
  • 2020-12-06 01:56

    There is no escape from the following construct, no matter what quotes you use:

    PASSWORD=$1
    doSQL "INSERT INTO active_records (password) VALUES (FROM_BASE64('$(echo -n $PASSWORD|base64)'))"
    
    0 讨论(0)
提交回复
热议问题