ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

shell编程---if语句

shell编程---if语句 if语句1、if..then..else...fi1 #! /bin/bash 2 echo $PWD 3 #if judagement condition expression 4 if grep shell ./1.txt /dev/null 5 #if grep Shell ./1.txt /dev/null 6 then 7 echo the string exists in in current path 8 else 9 echo the string dosent exist in current path 10 fiandyandy-virtual-machine:~/test_shell$cat 1.txtshellandyandy-virtual-machine:~/test_shell$2、if...then...fi1 #! /bin/bash 2 echo $PWD 3 #if judagement condition expression 4 if grep shell ./1.txt /dev/null 5 #if grep Shell ./1.txt /dev/null 6 then 7 echo the string exists in in current path 8 #else 9 # echo the string dosent exist in current path 10 fiandyandy-virtual-machine:~/test_shell$cat 1.txtshellandyandy-virtual-machine:~/test_shell$3、条件一直成立#! /bin/bash if true then printf Hello Shell Script\n fi4、if then elif then else fi#if then elif then if [[ $1 $2 $1 ! ]]; then echo $1; $2 elif [[ $1 test1 ]];then echo $1 elif [[ $2 test2 ]]; then echo Exit two option ...! else echo Exit the whole if...! fi #if then elif then if [[ $1 $2 $1 ! ]] then echo $1; $2 elif [[ $1 test1 ]] ;then echo $1 elif [[ $2 test2 ]];then echo Exit two option ...! else echo Exit the whole if...! fi运行结果1运行结果2then关键词需要注意事项then如果和if或者elif在一行前面需要加一个分号;then可以和语句在同一行。
返回列表