免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2205 | 回复: 8
打印 上一主题 下一主题

shell 中的 奇怪的*号,忘大侠解答 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-04-12 20:14 |只看该作者 |倒序浏览
#/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上面就有问题。

论坛徽章:
0
2 [报告]
发表于 2011-04-12 20:29 |只看该作者
试试去掉 转移符试试

论坛徽章:
0
3 [报告]
发表于 2011-04-12 22:22 |只看该作者
试试去掉 转移符试试
chenbin200818 发表于 2011-04-12 20:29



# 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
#

不转义的话,* 就是当前目录下的所有文件。

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
4 [报告]
发表于 2011-04-12 23:11 |只看该作者
回复 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\\\"";

论坛徽章:
0
5 [报告]
发表于 2011-04-12 23:31 |只看该作者
回复  songwubin007


    try: cmd="/usr/local/mysql-5.1.54/bin/mysql -uroot -p123456 -h192.168.1 ...
blackold 发表于 2011-04-12 23:11



    + 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

还是不行

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
6 [报告]
发表于 2011-04-12 23:35 |只看该作者
本帖最后由 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\;\\\""

论坛徽章:
0
7 [报告]
发表于 2011-04-13 10:50 |只看该作者
mysql不太熟,但是这个sql不需要where的吗?

论坛徽章:
0
8 [报告]
发表于 2011-04-13 11:12 |只看该作者
跟7楼有同样的疑问

论坛徽章:
0
9 [报告]
发表于 2011-04-13 12:30 |只看该作者
本帖最后由 dgww 于 2011-04-13 12:32 编辑

回复 7# oilz


   

取消\,然后加上where
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP