加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

if 语句for循环

发布时间:2020-12-15 23:25:32 所属栏目:安全 来源:网络整理
导读:9.27 shell 在shell脚本中,如果用户不输入东西,系统不自动退出,this is a bug! 文件测试语句:-d -f -r -w -x -e 逻辑测试语句:“”与(同时满足) “||”或(前为假,后面才实施) “
9.27

shell
在shell脚本中,如果用户不输入东西,系统不自动退出,this is a bug!
文件测试语句:-d -f -r -w -x -e
逻辑测试语句:“&&”与(同时满足) “||”或(前为假,后面才实施) “!”非(看中间是与还是或来决定)
整数值比较语句:eq(是否等于) gt(是否大于) lt(是否小于) ge(是否大于或等于) le(是否小于或等于) ne(是否不等于)
字符串比较语句:=(等于) !=(不等于) -z(是否为空)

if条件测试语句
if条件语句的单分支结构有ifthenfi 关键词组成,相当于口语的“如果...那么...”
#vi if.sh
#!/bin/bash
yt="/1/2/3/4"
if[ ! -e $yt] if [ -w $yt]
then
mkdir -p $yt chmod g+w $yt
fi #bash if.sh
#ll if.sh #ll -d /1/2/3/4
#bash if.sh

if条件语句的双分支结构由if、then、else、fi类似于口语“如果...那么...或者...那么...”
#vi if.sh
(‘DD‘删除)

#!/bin/bash
ping -c 3 -i 0.2 -w 3 $1 &>/dev/null
if[$? -eq 0]
then
echo"Host $1 is On-line."
else
echo"Host $1 is off-line."
fi
#chmod 777 if.sh
#./if.sh 192.168.26. ...

#! /bin/bash
read -p "please set directory: " n
if [ ! -e $n ]
then
mkdir -p $n
else
echo "this $n directory exist"
fi

#. /if.sh
xx
#ls
. /if.sh

#vi if.sh

#. /if.sh
70
80
90

#vi if.sh
#!/bin/bash
read -p "Enter your parameter : " n
if [ -e $n ] && [ -d $n ]
then
echo "this $n is directory"
elif [ -e $n ] && [ -f $n ]
then
echo "this $n is file "
else
echo "you enter is emputy"
fi

#./if.sh

for条件循环语句

语序一次性读取多个信息,然后逐一处理
#vi forlist.txt
a
b
c

#vi passwd.sh

#!/bin/bash
read -p "Enter The Users Password:" n
for u in ‘cat forlist’
..............

#ll forlist
#chmod 777 forlist
#chmod 777 passwd.sh
#ls
#./passwd.sh
#chmod 777 passwd.sh
#ll passwd.sh
#./passwd.sh

#vi ipaddr3个ip地址#vi foriplist.sh#bash foriplist.sh#chmod 777 forcheck.sh

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读