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.} 

내가 쉘의 매뉴얼을 보이지만, 무엇에 대해 아무것도 얻을 수 없습니다 "를?" 실제로 의미합니다.

사람의 강타 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이다 (첫 번째 위치 파라미터)

관련 문제