bash / linux中的报价问题

时间:2019-02-26 19:25:30

标签: mysql bash quotes

我有一个bash脚本,正在向其中添加一些SQL select语句,但是我度过了可怕的时间,无法正确读取它们。单引号,双引号等似乎并不快速,如果您希望像使用此一样使用整个sql语句。

示例:

declare -a array=(
'1=Unprocessed===SELECT count(*) FROM db.table WHERE thing1='unknown' and thing2='unknown' and thing3='unknown''
)

我已经厌倦了用单引号引起来-我已经厌倦了在整个过程中使用双引号。我已经尝试过使用单引号和双引号等

1 个答案:

答案 0 :(得分:1)

idk 1=Unprocessed===应该是什么,但这似乎是您要的:

$ declare -a array=(
'1=Unprocessed===SELECT count(*) FROM db.table WHERE thing1='\''unknown'\'' and thing2='\''unknown'\'' and thing3='\''unknown'\'''
)

$ echo "${array[0]}"
1=Unprocessed===SELECT count(*) FROM db.table WHERE thing1='unknown' and thing2='unknown' and thing3='unknown'
相关问题