使用函数 #!/bin/bash # testing the script function myfun { echo "This is an example of a function" } count=1 while [ $count -le 5 ] do myfun count=$[ $count +1 ] done echo "This is the end of the loop" myfun echo "Now this is the end…
碰到一个shell中函数调用的小问题,记录一下. shell中函数有三种调用方式,一种是在文件前面定义函数,然后在以下直接调用:一种是通过加载shell,在shell中直接调用:第三种是将函数写入文件.然后在其它shell中调用函数. 这里写一下关于第三种方法的样例: is_it_a_directory() { if [ $# -lt 1 ];then echo "is_it_a_directory:I need an argument" return 1 fi _DIRECTORY_…