shell中的函数
函数:功能, function 作用:代码重用 库:so function: 功能 结构化编程,不能独立运行,需要调用时执行,可以被多次调用 定义一个函数: function FUNCNAME { command } or FUNCNAME ( ) { command } 举例: # ! / bin / bash cat << EOF d | D ) show disk usages m | M ) show memory usages s | S ) show swap usages q | Q ) quit . EOF read - p "Your choice:" CHOICE until [ $ CHOICE == "q" - o $ CHOICE == "Q" ] ; do case $ CHOICE in d | D ) df - h ; ; m | M ) free - m | grep "^Mem" ; ; s | S ) free - m | grep "^Swap" ; ; * ) cat << EOF d | D ) show disk usages m | M ) show memory usages s | S ) show swap usages q | Q ) quit EOF read - p "Your choice:" CHOICE esac