linux shell 之if 您所在的位置:网站首页 linuxif判断 linux shell 之if

linux shell 之if

2024-06-23 11:13| 来源: 网络整理| 查看: 265

[macg@machome ~]$ vi test.sh

echo "input your choice:" read ANS    echo "input your choice:" read ANS

if [ $ANS = "Yes" -o $ANS = "yes" -o $ANS = "y" -o $ANS = "Y" ] then ANS="y" else ANS="n" fi

echo $ANS [macg@machome ~]$ sh test.sh input your choice: no n [macg@machome ~]$ sh test.sh input your choice: yes y [macg@machome ~]$ sh test.sh input your choice: y y  test 条件表达式 作为if条件=================================== if test $num -eq 0      等价于   if [ $num –eq 0 ]   test  表达式,没有 [  ]if test $num -eq 0                     man test [macg@machome ~]$ man test [(1)                             User Commands                            [(1)

SYNOPSIS        test EXPRESSION        [ EXPRESSION ]

       [-n] STRING               the length of STRING is nonzero          -n和直接$str都是非0条件

       -z STRING               the length of STRING is zero

       STRING1 = STRING2               the strings are equal

       STRING1 != STRING2               the strings are not equal

       INTEGER1 -eq INTEGER2               INTEGER1 is equal to INTEGER2

       INTEGER1 -ge INTEGER2               INTEGER1 is greater than or equal to INTEGER2

       INTEGER1 -gt INTEGER2               INTEGER1 is greater than INTEGER2

       INTEGER1 -le INTEGER2               INTEGER1 is less than or equal to INTEGER2

       INTEGER1 -lt INTEGER2               INTEGER1 is less than INTEGER2

       INTEGER1 -ne INTEGER2               INTEGER1 is not equal to INTEGER2

       FILE1 -nt FILE2               FILE1 is newer (modification date) than FILE2

       FILE1 -ot FILE2               FILE1 is older than FILE2

       -b FILE               FILE exists and is block special

       -c FILE               FILE exists and is character special

       -d FILE               FILE exists and is a directory

       -e FILE               FILE exists                                 文件存在

       -f FILE               FILE exists and is a regular file     文件存在且是普通文件

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

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

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

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

       -p FILE               FILE exists and is a named pipe

       -s FILE               FILE exists and has a size greater than zero

       -S FILE               FILE exists and is a socket

       -w FILE               FILE exists and is writable

       -x FILE FILE exists and is executable           && 如果是“前面”,则“后面” [ -f /var/run/dhcpd.pid ] && rm /var/run/dhcpd.pid    检查 文件是否存在,如果存在就删掉



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有