随笔-19  评论-21  文章-0  trackbacks-0
        对shell不熟,偶尔会现一些我无法理解的现象。此时该进行debug了,可选的方法有:
        a. echo变量的值 
        b. shell –x
   
        此外,Remember that the shell spends a lot of its life substituting text.(http://linuxcommand.org/wss0100.php)例如,对于下面的程序:
hex108@Gentoo ~ $ cat test.sh 
#!/bin/sh
var=
if [ $var = "y" ] ;then
    echo "yes"
fi
        if语句里的var变量经替换后变为 if [ = "y" ],些时当然会出错。
hex108@Gentoo ~ $ ./test.sh 
./test.sh: line 3: [: =: unary operator expected

          
        ps:现在写脚本的时候倾向于使用perl,而较少使用shell ,因为对于经常使用的脚本,可能会经常需要对它不停地进行改进,慢慢的,程序越来越大,该考虑重构了,   此时才会发现perl(python等“真正的”脚本语言)比shell相对来说更好重构。

posted on 2011-04-23 00:23 hex108 阅读(394) 评论(0)  编辑 收藏 引用 所属分类: Program

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理