分页: 1 / 1

关于脚本语言中if判断的问题

发表于 : 2013-05-04 15:09
Little_yan

代码: 全选

 1 #!/bin/bash
  2 #Program:
  3 #       This program shows using netstat and grep to detect WWW,SSHH,FTP,and            Mail services ports
  4 #History:
  5 #2013/05/04 13:48       yan     ninth release
  6 
  7 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  8 export PTAH
  9 
 10 testing=$ (netstat -tuln | grep ":80 ")
 11 if [ "$testing" != "" ];
 12 then
 13         echo "WWW is running in your system"
 14 fi
 15 testing=$ (netstat -tuln | grep ":22 ")
 16 if [ "$testing" != "" ];
 17 then
 18         echo "SSH is running in your system"
 19 fi
 20 testing=$ (netstat -tuln | grep ":21 ")
 21 if [ "$testing" != "" ];
 22 then
 23         echo "FTP is running in your system"
 24 fi
 25 testing=$ (netstat -tuln | grep ":25 ")
 26 if [ "$testing" != "" ];
 27 then
 28         echo "Mail is running in your system"
 29 fi
[/size]
想问问 第10行那个括号里的语法错了吗?我对着书写的说
错误的提示是这样的:
sh09.sh: line 10: syntax error near unexpected token `('
sh09.sh: line 10: `testing=$ (netstat -tuln | grep ":80 ")'
求高手帮忙, 要如何修改 :em06

Re: 关于脚本语言中if判断的问题

发表于 : 2013-05-04 15:33
YeLee
[bash]
#!/bin/bash
#Program:
# This program shows using netstat and grep to detect WWW,SSHH,FTP,and Mail services ports
#History:
#2013/05/04 13:48 yan ninth release

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PTAH

testing=$(netstat -tuln | grep ":80 ")
if [ "$testing" != "" ];
then
echo "WWW is running in your system"
fi
testing=$(netstat -tuln | grep ":22 ")
if [ "$testing" != "" ];
then
echo "SSH is running in your system"
fi
testing=$(netstat -tuln | grep ":21 ")
if [ "$testing" != "" ];
then
echo "FTP is running in your system"
fi
testing=$(netstat -tuln | grep ":25 ")
if [ "$testing" != "" ];
then
echo "Mail is running in your system"
fi

[/bash]
亲,下次贴代码的时候,能否先弄掉一些^\s*[0-9]*之类的东西啊,我的编辑器里面有高亮的,只要你代码没缺行多行便行。 :em01 :em01 :em01
至于你的那个问题呢?不知能否让那$跟括号不要离得太远了,尤其不要用空格隔着,隔着个空白符他们就找不到对方了。

Re: 关于脚本语言中if判断的问题

发表于 : 2013-05-04 17:05
Little_yan
YeLee 写了:[bash]
#!/bin/bash
#Program:
# This program shows using netstat and grep to detect WWW,SSHH,FTP,and Mail services ports
#History:
#2013/05/04 13:48 yan ninth release

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PTAH

testing=$(netstat -tuln | grep ":80 ")
if [ "$testing" != "" ];
then
echo "WWW is running in your system"
fi
testing=$(netstat -tuln | grep ":22 ")
if [ "$testing" != "" ];
then
echo "SSH is running in your system"
fi
testing=$(netstat -tuln | grep ":21 ")
if [ "$testing" != "" ];
then
echo "FTP is running in your system"
fi
testing=$(netstat -tuln | grep ":25 ")
if [ "$testing" != "" ];
then
echo "Mail is running in your system"
fi

[/bash]
亲,下次贴代码的时候,能否先弄掉一些^\s*[0-9]*之类的东西啊,我的编辑器里面有高亮的,只要你代码没缺行多行便行。 :em01 :em01 :em01
至于你的那个问题呢?不知能否让那$跟括号不要离得太远了,尤其不要用空格隔着,隔着个空白符他们就找不到对方了。
:em06 不好意思~怕太小看不清~
谢谢你~又再次帮助我解决问题~
这样有学到东西了~

Re: 关于脚本语言中if判断的问题

发表于 : 2013-05-05 10:42
leofun
想问问楼主是在跟着哪本书在学习脚本呢?推荐给我看看,我也打算学学脚本的

Re: 关于脚本语言中if判断的问题

发表于 : 2013-05-05 21:10
Little_yan
leofun 写了:想问问楼主是在跟着哪本书在学习脚本呢?推荐给我看看,我也打算学学脚本的
其实我也是看网上推荐的 我看 鸟哥的Linux私房菜 这本书
希望对你有帮助