eg:

Expect:

1.用环境变量RANDOM随机生成一个100以内的随机数

2.read读取当前输入

3.当前输入对比随机生成的数

4.当两个数相等时跳出苏循环,并计数(比较n次结果才相等)

 #!/bin/bash
i=
num=$(expr $RANDOM % )
echo $num
while true
do
let i++
read -p "Please input number(1-100):" digit
if [ $digit -eq $num ]; then
echo $digit
echo "一共$i 次!!"
break
elif [ $digit -lt $num ]; then
echo "The number is less!"
elif [ $digit -gt $num -o $digit -gt ]; then
echo "The number is bigger"
#elif [ $digit -gt 100 ]; then
# echo "not in the range!! Please reinput."
else
continue
fi
done

eg:

复习简单实例 ,    简单输入n次要取得值,最后打印出获得的所有值

 #!/bin/bash
attr=()
num=
while true
do
read -p ">>input:" name
attr[$num]=$name
echo ${attr[$num]}
let num++
if [ $num -eq ]; then
echo ${attr[*]}
exit
fi
done

eg:for循环

eg:continue和break的区别

  continue结束本次循环,进行下一次循环

  break跳过本次循环

 #!/bin/bash
for i in `seq `
do
if [ $i -eq ]; then
continue
else
echo $i
fi
done #!/bin/bash
int=
while :
do
let int++
if [ $int -lt ]; then
echo $int
else
break
fi
done
====================
for循环的用法
#!/bin/bash
for ((a=;a<;a++))
do
echo $a
done
====================
嵌套循环
#!/bin/bash
for ((a=;a<;a++))
do
echo "outer loop: $a"
for ((b=;b<;b++))
do
if [ $b -eq ]; then
continue
else
echo "inner loop: $b"
fi
done
done
====================

shell脚本编写添加用户,随机密码后五位

 #!/bin/bash
for ((i=;i<;i++))
do
password=`openssl rand -hex | cut -c1-`
echo "$password"
cat /etc/passwd|grep -qa user$i
if [ $? -eq ]; then
echo "user${i} already"
continue
else
useradd user$i;echo $a|passwd --stdin user$i
fi
done

最新文章

  1. 动态添加LinearLayout的高度
  2. 利用git+hugo+markdown 搭建一个静态网站
  3. TCP协议与UDP协议的区别
  4. 【OpenGL】 第一篇 OpenGL概览
  5. ruby 学习笔记 1
  6. 【原】redux学习笔记
  7. sublime文档
  8. Unity项目在亚马逊KindleFire设备上旋转不正确的解决方案
  9. Centos环境下部署游戏服务器-Eclipse
  10. c++之函数原型
  11. JAVA-应用easyui
  12. Githut Token (hidden): Githut 安装验证
  13. gridcontrol显示行号,总行,打印,导出Excel,设置标头及内容居中方法
  14. SQL Server实现远程访问
  15. dt转换List CovertListHelper
  16. linux无法启动httpd服务问题
  17. 《计算机网络》-CCNA命令大全
  18. natapp 穿透访问 vue项目 Invalid Host header
  19. (转)SQL知识_SqlParameter数组
  20. Global.asax 详解

热门文章

  1. Go服务监控
  2. [考试反思]0914csp-s模拟测试43:破绽
  3. spring boot打包成war包的页面该放到哪里?
  4. Apache服务及个人用户主页功能和密码验证
  5. wangkoala杂题总集(根据个人进度选更)
  6. 利用JaCoCo统计接口测试中代码覆盖率
  7. MyBatis动态语句if与choose的区别
  8. 【最新发布】最新Python学习路线,值得收藏
  9. 除了获取 MAC 地址还能干啥
  10. hdu 1028 Sample Ignatius and the Princess III (母函数)