一、shell里面if能嵌套多少层
7层,可以嵌入if函数7层
二、怎么写一个shell脚本传入参数
很简单,写个循环 if[$#-eq0]##判断参数是否存在 then exit##不存在退出 else forain$*##存在话,取参数放入a中循环 do b=`echo$a|tr[a-z][A-Z]`###将a改成大写 echo"CC"$b##拼接成功CCA done fi
三、shell里for循环可以嵌套if吗
我的回答:可以嵌套。
shell里面for循环是可以嵌套if条件语句的。
举例:
foriin`cat/etc/ansible/iplist`;do
ifecho$i|grep"192";then
pass='Abc@123'
echo"$iansible_ssh_port=22ansible_ssh_user=rootansible_user_pass=\"$pass\p"">>/etc/ansible/hosts
else
echo$i>>/etc/ansible/hosts
fi
done
四、shell if else判断两数相等
if[$x-eq$y]------------if[$x-eq$y]----------[]两边都要有空格echo"inputtwonumber:"readxreadyif[$x-eq$y]thenecho"equal!"elseecho"notequal"fi
好了,本文到此结束,如果可以帮助到大家,还望关注本站哦!