-bash:意外令牌')'附近的语法错误 [英] -bash: syntax error near unexpected token `)'

查看:62
本文介绍了-bash:意外令牌')'附近的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能缺少一些非常基本的东西.我有一个Web脚本,该脚本告诉Shell脚本更新一些数据库记录.这些记录用于统计,因此在更新数据库记录时,Web脚本不必等待.但是,我实际上无法使Shell脚本能够从命令行运行它.这是我正在尝试的代码:

I'm probably missing something very basic. I have a web script that tells a shell script to update some database records. These records are for statistics, and this way the web script does not have to wait while the database records are updated. However, I can't actually make the shell script work running it from commandline. Here is the code that I'm trying:

perl async_sql.pl 'UPDATE some_table set i = i + 1 WHERE (n in (\'328430\',\'334969\',\'330179\',\'335290\',\'335285\',\'335284\',\'335264\',\'335145\',\'335146\',\'335147\',\'335148\',\'335149\',\'335230\',\'335201\',\'335198\',\'335196\',\'335167\',\'335151\',\'335152\',\'335143\',\'334969\',\'334972\',\'334977\',\'334978\',\'334979\',\'334980\',\'334982\',\'334983\',\'334984\',\'334934\',\'334947\',\'334948\',\'334950\',\'334992\',\'335014\',\'335026\',\'335030\',\'335032\',\'334864\',\'334862\',\'334861\',\'334858\',\'334855\',\'334852\',\'334850\',\'334849\',\'334848\',\'334847\',\'334844\',\'334842\'))'

Bash告诉我:

-bash:意外令牌')'附近的语法错误

-bash: syntax error near unexpected token `)'

我想念什么?

推荐答案

无法在单引号中转义单引号.使用" 代替

It is not possible to escape single quote in single quotes. Use " " instead

perl async_sql.pl "UPDATE some_table set i = i + 1 WHERE (n in ('328430','334969','330179','335290','335285','335284','335264','335145','335146','335147','335148','335149','335230','335201','335198','335196','335167','335151','335152','335143','334969','334972','334977','334978','334979','334980','334982','334983','334984','334934','334947','334948','334950','334992','335014','335026','335030','335032','334864','334862','334861','334858','334855','334852','334850','334849','334848','334847','334844','334842'))"


另外,还有其他方法可以解决此问题:


Also, there are other ways to deal with this problem:

echo "quote'test"
echo 'quote'"'"'test'
echo 'quote'\''test'
echo $'quote\'test'

所有这些都应将 quote'test 作为单个参数打印出来.这意味着您的问题的另一个不错的解决方案是:

All these should print quote'test as a single parameter. Which means that another great solution for your problem is:

perl async_sql.pl $'UPDATE some_table set i = i + 1 WHERE (n in (\'328430\',\'334969\',\'330179\',\'335290\',\'335285\',\'335284\',\'335264\',\'335145\',\'335146\',\'335147\',\'335148\',\'335149\',\'335230\',\'335201\',\'335198\',\'335196\',\'335167\',\'335151\',\'335152\',\'335143\',\'334969\',\'334972\',\'334977\',\'334978\',\'334979\',\'334980\',\'334982\',\'334983\',\'334984\',\'334934\',\'334947\',\'334948\',\'334950\',\'334992\',\'335014\',\'335026\',\'335030\',\'335032\',\'334864\',\'334862\',\'334861\',\'334858\',\'334855\',\'334852\',\'334850\',\'334849\',\'334848\',\'334847\',\'334844\',\'334842\'))'

我只在参数前放置了一个美元符号 $ .就是这样.在单引号前加一个美元符号 ANSI-C报价

I have only placed a dollar sign $ right before the parameter. That's it. A dollar sign before single quotes turns on ANSI-C Quoting

这篇关于-bash:意外令牌')'附近的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆