shell 指令碼經典框架案例

2020-08-12 14:41:14

shell 指令碼經典框架案例

#!/bin/bash

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

test(){
if [ "$#" -ne 2 ];then
	echo '你輸入的變數數量不對。。'
	return 1
else
	accept="$@"
	accepts=`echo $accept|awk '{print $2}'`
	expr 1 + $accepts &>/dev/null
	if [ "$?" -ne 0 ];then
		echo "你輸入的第二個值不是數位."
		return 1
	else
		echo "$@"
	fi
fi	
}

main(){
test $1 $2
if [ $? -eq 1 ];then
	exit 1
fi
}

main $1 $2