[英]what does “:?” mean in this shell command?
這是shell腳本:
#!/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.}
我在尋找shell手冊,但對“:?”一無所知 其實是說
謝謝
來自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(第一個位置參數)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.