六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 34|回复: 0

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

[复制链接]

升级  4.33%

63

主题

63

主题

63

主题

举人

Rank: 3Rank: 3

积分
213
 楼主| 发表于 2013-2-4 12:58:13 | 显示全部楼层 |阅读模式
<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"
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表