#! /bin/sh
func(){
echo "this is my first shell func"
}
echo "start the func"
func
echo "end"
2.运用函数体验函数编程
#! /bin/sh
is_directory(){
DIR_NAME=$1
if [ ! -d $DIR_NAME ]; then
return 1
else
return 0
fi
}
for DIR in "$@"; do
if is_directory "$DIR"
then :
else
echo "$DIR is not exist, Creating it now..."
mkdir $DIR > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Cannot create directory $DIR_NAME"
exit 1
fi
fi
done