码迷,mamicode.com
首页 > 其他好文 > 详细

basic bash learning 1

时间:2019-10-06 18:27:45      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:==   color   java   echo   not   fun   head   done   dmi   

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

标签:==   color   java   echo   not   fun   head   done   dmi   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!