【问题标题】:How to issue a statement containing single quotes from a bash script如何从 bash 脚本发出包含单引号的语句
【发布时间】:2012-09-27 04:42:48
【问题描述】:

我尝试在我的一个脚本中执行以下 mysql 命令:

mysql -e 'show global status like 'open_files''

但它似乎不起作用,因为字符串 'open_files' 周围有单引号。

我怎样才能发出这样一个包含单引号的命令?

【问题讨论】:

  • 如果这行报错了,能发一下吗?
  • 改用"open files"

标签: mysql mysql-python


【解决方案1】:

在外面使用双引号。

mysql -h127.0.0.1 -uxxxxx -pxxxxx -A databasename -e "show global status like 'open_files'"

或相反的方式:

mysql -h127.0.0.1 -uxxxxx -pxxxxx -A databasename -e 'show global status like "open_files"'

或者你可以转义单引号。

而你使用的是LIKE,你是不是错过了%的野字符?

【讨论】:

    猜你喜欢
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-24
    • 2012-05-30
    • 1970-01-01
    • 2021-02-22
    相关资源
    最近更新 更多