shell 中的 奇怪的*号,忘大侠解答
#/bin/sh
user="root"
cmd="/usr/local/mysql-5.1.54/bin/mysql -uroot -p123456 -h192.168.1.124 -e \"select \* from mysql.user user='$user' limit 1\"";
eval $cmd
#---------结果--------------
ERROR at line 1: Unknown command '\*'.
上面的程序在ubuntu 10.04 server 上没有问题,但是在 ubuntu 10.10 和 rs 5上面就有问题。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
试试去掉 转移符试试
# ls
a.sh bin mysql.sock psql.lock tmp_rs
# ./a.sh
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql.sock psql.lock tmp_rs from mysql.user user='root' limit 1' at line 1
#
#
#
# sh -x a.sh
+ user=root
+ cmd=/usr/local/mysql-5.1.54/bin/mysql -ureadonly -p123456 -h192.168.1.153 -e "select * from mysql.user user='root' limit 1"
+ eval /usr/local/mysql-5.1.54/bin/mysql -ureadonly -p123456 -h192.168.1.153 -e "select a.sh bin mysql.sock psql.lock tmp_rs from mysql.user user='root' limit 1"
+ /usr/local/mysql-5.1.54/bin/mysql -ureadonly -p123456 -h192.168.1.153 -e select a.sh bin mysql.sock psql.lock tmp_rs from mysql.user user='root' limit 1
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql.sock psql.lock tmp_rs from mysql.user user='root' limit 1' at line 1
#
不转义的话,* 就是当前目录下的所有文件。
回复 1# songwubin007
try: cmd="/usr/local/mysql-5.1.54/bin/mysql -uroot -p123456 -h192.168.1.124 -e \\\"select \* from mysql.user user='$user' limit 1\\\"";
+ user=root
+ cmd=/usr/local/mysql-5.1.54/bin/mysql -ureadonly -p123456 -h192.168.1.153 -e \"select \* from mysql.user where user='root' limit 1\"
+ eval /usr/local/mysql-5.1.54/bin/mysql -ureadonly -p123456 -h192.168.1.153 -e \"select \* from mysql.user where user='root' limit 1\"
+ /usr/local/mysql-5.1.54/bin/mysql -ureadonly -p123456 -h192.168.1.153 -e "select * from mysql.user where user=root limit 1"
/usr/local/mysql-5.1.54/bin/mysql Ver 14.14 Distrib 5.1.54, for unknown-linux-gnu (x86_64) using EditLine wrapper
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Usage: /usr/local/mysql-5.1.54/bin/mysql [OPTIONS] [database]
-?, --help Displa
还是不行
本帖最后由 blackold 于 2011-04-12 23:41 编辑
回复 5# songwubin007
是不是省了尾分号
try: cmd="/usr/local/mysql-5.1.54/bin/mysql -uroot -p123456 -h192.168.1.124 -e \\\"select \* from mysql.user user='$user' limit 1\;\\\""
mysql不太熟,但是这个sql不需要where的吗?
跟7楼有同样的疑问
本帖最后由 dgww 于 2011-04-13 12:32 编辑
回复 7# oilz
取消\,然后加上where