2012-03-06 4 views
0

はシェルスクリプトです:":?"このシェルコマンドの意味ですか?ここ

#!/bin/bash 

version="0.01"; 

fibonacci() { 
    n=${1:?If you want the nth fibonacci number, you must supply n as the first parameter.} 
    if [ $n -le 1 ]; then 
    echo $n 
    else 
    l=`fibonacci $((n-1))` 
    r=`fibonacci $((n-2))` 
    echo $((l + r)) 
    fi 
} 

for i in `seq 1 10` 
do 
    result=$(fibonacci $i) 
    echo "i=$i result=$result" 
done 

、私はこのラインについて混乱しに来る:

n=${1:?If you want the nth fibonacci number, you must supply n as the first parameter.} 

私はシェルのマニュアルを探しますが、何をするかについては何も取得しない「:を?」実際には意味する。男のbashから

THX

答えて

5

${parameter:?word} 
      Display Error if Null or Unset. If parameter is null or unset, the expansion of word 
      (or a message to that effect if word is not present) is written to the standard error 
      and the shell, if it is not interactive, exits. Otherwise, the value of parameter is 
      substituted. 

この場合、チェックされているパラメータが$(第1位置パラメータ)

あります
関連する問題