免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: wwr
打印 上一主题 下一主题

[系统管理] 有关判断变量是否为空的疑问---新年也不忘写脚本啊有木有! [复制链接]

论坛徽章:
60
20周年集字徽章-20	
日期:2020-10-28 14:04:3015-16赛季CBA联赛之北京
日期:2016-07-06 15:42:0715-16赛季CBA联赛之同曦
日期:2016-06-12 10:38:0915-16赛季CBA联赛之佛山
日期:2016-05-27 11:54:56黄金圣斗士
日期:2015-12-02 11:44:35白银圣斗士
日期:2015-11-25 14:32:43白银圣斗士
日期:2015-11-23 12:53:352015亚冠之布里斯班狮吼
日期:2015-10-21 16:55:482015亚冠之首尔
日期:2015-09-01 16:46:052015亚冠之德黑兰石油
日期:2015-08-31 11:39:192015亚冠之萨济拖拉机
日期:2015-08-28 21:06:5315-16赛季CBA联赛之广东
日期:2016-07-12 14:58:53
11 [报告]
发表于 2013-01-02 11:40 |只看该作者
回复 5# wwr


    [ ! -z "$var" ] 跟 [ -n "$var" ] 是一个效果
  1. [root@centos ~]# man test
  2. TEST(1)                          User Commands                         TEST(1)

  3. NAME
  4.        test - check file types and compare values

  5. SYNOPSIS
  6.        test EXPRESSION
  7.        test

  8.        [ EXPRESSION ]
  9.        [ ]
  10.        [ OPTION

  11. DESCRIPTION
  12.        Exit with the status determined by EXPRESSION.

  13.        --help display this help and exit

  14.        --version
  15.               output version information and exit

  16.        An omitted EXPRESSION defaults to false.  Otherwise, EXPRESSION is true or false and sets exit status.  It is one of:

  17.        ( EXPRESSION )
  18.               EXPRESSION is true

  19.        ! EXPRESSION
  20.               EXPRESSION is false

  21.        EXPRESSION1 -a EXPRESSION2
  22.               both EXPRESSION1 and EXPRESSION2 are true

  23.        EXPRESSION1 -o EXPRESSION2
  24.               either EXPRESSION1 or EXPRESSION2 is true

  25.        -n STRING
  26.               the length of STRING is nonzero

  27.        STRING equivalent to -n STRING

  28.        -z STRING
  29.               the length of STRING is zero

  30.        STRING1 = STRING2
  31.               the strings are equal

  32.        STRING1 != STRING2
  33.               the strings are not equal

  34.        INTEGER1 -eq INTEGER2
  35.               INTEGER1 is equal to INTEGER2

  36.        INTEGER1 -ge INTEGER2
  37.               INTEGER1 is greater than or equal to INTEGER2

  38.        INTEGER1 -gt INTEGER2
  39.               INTEGER1 is greater than INTEGER2

  40.        INTEGER1 -le INTEGER2
  41.               INTEGER1 is less than or equal to INTEGER2

  42.        INTEGER1 -lt INTEGER2
  43.               INTEGER1 is less than INTEGER2

  44.        INTEGER1 -ne INTEGER2
  45.               INTEGER1 is not equal to INTEGER2

  46.        FILE1 -ef FILE2
  47.               FILE1 and FILE2 have the same device and inode numbers

  48.        FILE1 -nt FILE2
  49.               FILE1 is newer (modification date) than FILE2

  50.        FILE1 -ot FILE2
  51.               FILE1 is older than FILE2

  52.        -b FILE
  53.               FILE exists and is block special

  54.        -c FILE
  55.               FILE exists and is character special

  56.        -d FILE
  57.               FILE exists and is a directory

  58.        -e FILE
  59.               FILE exists

  60.        -f FILE
  61.               FILE exists and is a regular file

  62.        -g FILE
  63.               FILE exists and is set-group-ID

  64.        -G FILE
  65.               FILE exists and is owned by the effective group ID

  66.        -h FILE
  67.               FILE exists and is a symbolic link (same as -L)

  68.        -k FILE
  69.               FILE exists and has its sticky bit set

  70.        -L FILE
  71.               FILE exists and is a symbolic link (same as -h)

  72.        -O FILE
  73.               FILE exists and is owned by the effective user ID

  74.        -p FILE
  75.               FILE exists and is a named pipe

  76.        -r FILE
  77.               FILE exists and read permission is granted

  78.        -s FILE
  79.               FILE exists and has a size greater than zero

  80.        -S FILE
  81.               FILE exists and is a socket

  82.        -t FD  file descriptor FD is opened on a terminal

  83.        -u FILE
  84.               FILE exists and its set-user-ID bit is set

  85.        -w FILE
  86.               FILE exists and write permission is granted

  87.        -x FILE
  88.               FILE exists and execute (or search) permission is granted

  89.        Except  for  -h and -L, all FILE-related tests dereference symbolic links.  Beware that parentheses need to be escaped (e.g., by back-
  90.        slashes) for shells.  INTEGER may also be -l STRING, which evaluates to the length of STRING.

  91.        NOTE: your shell may have its own version of test and/or [, which usually supersedes the version described here.  Please refer to your
  92.        shell’s documentation for details about the options it supports.

  93. AUTHOR
  94.        Written by Kevin Braunsdorf and Matthew Bradburn.

  95. REPORTING BUGS
  96.        Report bugs to <bug-coreutils@gnu.org>.

  97. COPYRIGHT
  98.        Copyright ? 2006 Free Software Foundation, Inc.
  99.        This   is   free   software.    You   may   redistribute   copies   of   it  under  the  terms  of  the  GNU  General  Public  License
  100.        <http://www.gnu.org/licenses/gpl.html>.  There is NO WARRANTY, to the extent permitted by law.

  101. SEE ALSO
  102.        The full documentation for test is maintained as a Texinfo manual.  If the info and test programs are properly installed at your site,
  103.        the command

  104.               info test

  105.        should give you access to the complete manual.

  106. test 5.97                        February 2010                         TEST(1)
复制代码

论坛徽章:
1
辰龙
日期:2014-05-22 11:38:58
12 [报告]
发表于 2013-01-02 21:07 |只看该作者
回复 8# waker


    学习了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP