请问如下脚本错在哪里?搞了老半天了。
时间:2011-03-02
来源:互联网
脚本内容:
#!/bin/bash
ip=$1
if [ -s /tmp/a.txt ];then
case "$ip" in
"10.10.1.1")
echo "IPaddress is 10.10.1.1" >> a.txt
;;
case "$ip" in
"10.10.2.1")
echo "IPaddress is 10.10.2.1" >> a.txt
;;
esac
fi
exit
执行结果:
[root@RHEL54 tmp]# sh -x test.sh "10.10.1.1"
+ ip=10.10.1.1
test.sh: line 8: syntax error near unexpected token `"$ip"'
test.sh: line 8: `case "$ip" in '
[root@RHEL54 tmp]# sh -x test.sh "10.10.2.1"
+ ip=10.10.2.1
test.sh: line 8: syntax error near unexpected token `"$ip"'
test.sh: line 8: `case "$ip" in '
[root@RHEL54 tmp]#
作者: anderlee 发布时间: 2011-03-02
作者: chenbin200818 发布时间: 2011-03-02
两个 ?
作者: 南极雨 发布时间: 2011-03-02
ip=$1
if [ -s /tmp/a.txt ];then
case "$ip" in
"10.10.1.1")
echo "IPaddress is 10.10.1.1" >> a.txt
;;
esac
case "$ip" in
"10.10.2.1")
echo "IPaddress is 10.10.2.1" >> a.txt
;;
esac
fi
exit
作者: gregorian 发布时间: 2011-03-02
两个case...esac。头脑迷糊了,清醒一点再看看。
作者: anderlee 发布时间: 2011-03-02
2楼正解。
作者: where27 发布时间: 2011-03-02
作者: chenbin200818 发布时间: 2011-03-02
作者: L_kernel 发布时间: 2011-03-02
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28