quanminchaoren 发表于 2013-2-4 12:58:13

Linux Shell脚本文件的判断、中文符号及其字符串入参解析

<div class="article_content">1、shell脚本中判断文件是否存在 if [ -f  "$var" ] then......
2、shell脚本中判断字符串为空  if [ -z "$str"] then......
3、shell脚本中判断字符串不为空 if[ "$str"] then.....
4、字符串入参的注意事项
      将字符串当做入参时,要用""引起来。在脚本中使用字符串入参时,有两种方式(脚本如下:实现在屏幕指定位置输出字符串的功能)
        #!/bin/sh
        tput init
        row=$1
        str=$2  #此处接收字符串参数 不必用""
        echo $str
        len=`expr length "$str"`    #此处使用$str参数时,需要用""引起来
        # 若不用expr 则可考虑 len=`echo $str | wc -c` 此时$str可不用""引起来
        colnum=`tput cols`
        show_col=`expr /( $colnum - $len /) / 2`
        tput sc
        tput cup $row $show_col
        echo "$str"
页: [1]
查看完整版本: Linux Shell脚本文件的判断、中文符号及其字符串入参解析