basic bash learning 1

Posted amy2012

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 ~]$

  

以上是关于basic bash learning 1的主要内容,如果未能解决你的问题,请参考以下文章

Machine Learning- Basics

CSE 6363 - Machine Learning Homework MLE, MAP, and Basic Supervised Learning

Machine Learning Pre-Basics

Machine Learning Pre-Basics

Machine Learning Basics

Machine Learning Basics