When a variable is evaluated in a script, you need to add a [] to the outside and set a $
[email protected] tmp]# cat real_mem_used01.sh
#!/bin/bash
Total= ' Free-g|grep Mem |awk ' {print $} '
Used= ' Free-g|grep Mem |awk ' {print $} '
Buffer= ' Free-g|grep Mem |awk ' {print $6} '
Cache= ' Free-g|grep Mem |awk ' {print $7} '
real_used=$[$USED-$BUFFER-$CACHE]
pused=$[$real _used*100/$TOTAL]
echo $PUSED%
[Email protected] tmp]#
[Email protected] tmp]# sh real_mem_used01.sh
12%
[Email protected] tmp]#
Method Two:
[email protected] tmp]# cat aa.sh
#!/bin/bash
Real_used= ' Free-g|grep cache |grep ': ' |awk ' {print $} '
Total= ' Free-g|grep Mem|awk ' {print $} '
awk ' begin{printf '%.2f\n ', (' $Real _used '/' $Total ') *100} '
[Email protected] tmp]# sh aa.sh
10.64
[Email protected] tmp]#
Recursive use of variables in shell scripts--Real memory usage view scripts