引数の数を判定する件数
関数名 Arg_Nums
書式 Arg_Nums 比較用演算子 比較用数値 "$@"
目的 呼び出し元スクリプトの実行にに必要な引数の数を判定する
戻り値 条件を満たす:0 条件を満たさない:1 エラー:9
Arg_Nums (){ . Error_Msg.sh && . Char_Type.sh ||\ { echo "Arg_Nums: error: Funciton not found." 1>&2; exit 9; } local _ARG= local _CMPR_OPRT=$1 local _CMPR_NUM=$2 #変数の内容が比較演算子であることを確認 case $_CMPR_OPRT in -lt|-le|-ne|-eq|-ge|-gt) : ;; *) Error_Msg Arg_Nums "Conparison operator not found." exit 9 ;; esac #変数の内容が数値であることを確認 Char_Type $_CMPR_NUM if [ $? -ne 1 ]; then Error_Msg Arg_Nums "Comparison number not found." exit 9 fi #オプションを除く引数の数か期待するものであるかを判定 shift 2 for _ARG in "$@"; do [ "$_ARG" = "" ] && return 1 done if [ "$#" "$_CMPR_OPRT" "$_CMPR_NUM" ]; then return 0 else return 1 fi }