12 2016 档案

shell while循环体猜数字
摘要:#! /bin/bash echo "guest the num from 1 to 10" read num while [ $num != 5 ] do if [ $num -lt 5 ] then echo "Too small,try agin" read num elif [ $num -gt 5 ] then echo "Too large,try agin" read num fi... 阅读全文

posted @ 2016-12-12 22:46 leonardhelloworld 阅读(747) 评论(0) 推荐(0)

shell 使用Seq算出1-100的奇数之和
摘要:#! /bin/bash echo 计算出1-100的奇数之和 sum=0 for i in $( seq 1 2 100) do let "sum+=i" done echo result=$sum [root@lenny Desktop]# ./countjishu.sh 计算出1-100的奇数之和 result=2500 阅读全文

posted @ 2016-12-11 12:55 leonardhelloworld 阅读(1845) 评论(0) 推荐(0)

Shell脚本判断是否是闰年
摘要:#! /bin/bash echo -n Input year to judge if it is a leap year: read year let "y1=$year % 4" let "y2=$year % 100" let "y3=$year % 400" if [ ! "$y1" -eq 0 ] then leap=0 elif [ ! "$y2" -eq 0 ] then leap... 阅读全文

posted @ 2016-12-10 20:06 leonardhelloworld 阅读(4472) 评论(0) 推荐(1)

shell脚本之使用bc工具实现数值转换(浮点转二进制)
摘要:#! /bin/bash echo -n input float: read num echo power of the operation: echo $num^2 |bc echo converted to binary echo "obase=2;$num" |bc [root@lenny Desktop]# ./zhuanhuan.sh input float:3.1415... 阅读全文

posted @ 2016-12-10 12:51 leonardhelloworld 阅读(884) 评论(0) 推荐(0)

shell脚本之函数的参数
摘要:#! /bin/bash echo use function hello() { echo how many parameters in the function:$#; echo the name of this function is $0; echo the first parameters is :$1; echo the second parameters is :$2; } hel... 阅读全文

posted @ 2016-12-10 12:13 leonardhelloworld 阅读(6995) 评论(0) 推荐(0)

shell脚本之while
摘要:#! /bin/bash echo if num smaller than 5,it will continue num=0 while [ $num -lt 5 ] do echo now the num is $num let num++ done [root@lenny Desktop]# ./while.sh if num smaller than 5,it will c... 阅读全文

posted @ 2016-12-10 11:52 leonardhelloworld 阅读(232) 评论(0) 推荐(0)

shell脚本之for循环
摘要:#! /bin/bash echo what programming lanuages do you know? for i in python C# java ruby perl do echo i know : $i done [root@lenny Desktop]# ./for.sh what programming lanuages do you know? i kno... 阅读全文

posted @ 2016-12-10 11:41 leonardhelloworld 阅读(339) 评论(0) 推荐(0)

shell 脚本中使用case查看登陆用户
摘要:#! /bin/bash case $USERNAME in "student")echo u r using student;; "leonard")echo u r using leonard;; *)echo u r using other account;; esac 阅读全文

posted @ 2016-12-09 23:39 leonardhelloworld 阅读(249) 评论(0) 推荐(0)

Shell脚本中使用test测试命令测试数值
摘要:101是否小于或等于99 类似的特殊符号还有 -eq 【判断是否相等】 -ge 【判断是否大于或等于】 -lt 【判断是否小于】 -ne 【判断是否不等于】 可以使用命令“[]”代替test命令来作为逻辑表达式 阅读全文

posted @ 2016-12-09 23:08 leonardhelloworld 阅读(484) 评论(0) 推荐(0)

导航