basic bash learning 1

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 ~]$

  

猜你喜欢

转载自www.cnblogs.com/amy2012/p/11627797.html