首页 > 其他 > 详细

basic bash learning 1

时间:2019-10-06 18:30:49      阅读:67      评论:0      收藏:0      [点我收藏+]

1) a function to check the free memory:

[admin@appsvr ~]$ function checkmem(){
> echo -n "The amount of free memeory is "
> free |head -2|tail -1|awk ‘{print $4}‘
> }
[admin@appsvr ~]$ checkmem
The amount of free memeory is 107940

  

2) using for loop to print the odd number from 1 to 99

for number in {1..99..2}
do
echo $number
done

 

3)  If and case

#!/bin/bash
read X
read Y
if (( $X > $Y )); then
printf "X is greater than Y"
elif (( $X == $Y )); then
printf "X is equal to Y"
else
printf "X is less than Y"
fi

#!/bin/bash
read p
case $p in 
Y|y) echo "YES" ;;
N|n) echo "NO" ;;
esac

4. delete the function name from terminal

[admin@appsvr ~]$ unset -f checkmem
[admin@appsvr ~]$ checkmem
bash: checkmem: command not found...
[admin@appsvr ~]$

  

basic bash learning 1

原文:https://www.cnblogs.com/amy2012/p/11627797.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!