-1

当我编写参数时,它们应该在一个案例中进行检查,然后添加到一个列表中,如果你在前面输入 -c,参数应该是大写的,如果你输入 -4,参数应该出现 4 次

#!/bin/bash

function forloop {
for each in naam
do
echo  $naam zegt je dat...

echo ""
echo 

let "x+=1"

done
}

function helper {
echo "use names only."
echo "if u type -c before a word then it wil be shown in capital"
echo "if u type -(number) before a word the word will be shown (number)times "

}


naam=null
x=0

while [ $x -le 4 ]
do

case $1 in

    -c) echo "${2 ^^}";shift ;;
    help) helper ;shift;naam=helper;;
    -4) $1x-1 
    exit ;shift;;

esac

naam=" $1"

shift
forloop

done

exit
4

1 回答 1

1
#!/bin/bash

if [ -z "$1" ]
then
 echo "use names only."
 echo "if you type -c before a word, then it will be shown in capitals"
 echo "if you type -NUMBER before a word, the word will be shown NUMBER times"
 exit
fi

while [ $1 ]
do
    case $1 in
    -c)     shift; <<<$1 tr '[:lower:]' '[:upper:]';;
    -[0-9]*)for ((count=$1; count++; )) do echo $2; done; shift;;
    *)      echo $1
    esac
    shift
done
于 2013-05-28T08:45:32.537 回答