что значит ":?"значит в этой командной оболочке? - PullRequest
0 голосов
/ 06 марта 2012

вот сценарий оболочки:

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

1 Ответ

5 голосов
/ 06 марта 2012

от man bash:

${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 (первый позиционный параметр)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...