2013-05-27 37 views
-1

當我寫參數時,他們應該在案件中檢查,然後添加到列表中,如果你在前面輸入-c參數應該是大寫,如果你鍵入-4參數應該出現4次如何結合案例和班次,並在bash中添加結果列表

#!/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 
+0

哪部分代碼導致您的問題? –

+1

對於$ naam中的每一個,你都缺少'$'。我無法弄清楚你打算用'$ 1x-1'。 – Barmar

回答

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