謝謝你的幫助。我做錯了什么,在這里?我希望在回圈中使用數字答案,但它沒有回傳我所期望的:
if [ "$#" -eq 0 ]; then
echo -n "Enter the number: "
read answer
else
answer=( "$@" )
fi
for i in {1..$answer} ; do echo ${i}; done
執行時,我有這個:
me@local misc]$ ./test.sh
Enter the number: 5
{1..5}
我希望回聲回傳 1 2 3 4 5
uj5u.com熱心網友回復:
你也可以這樣做:
if [ "$#" -eq 0 ]; then
echo -n "Enter the number: "
read answer
else
answer=( "$@" )
fi
for i in $(seq 1 $answer) ; do echo ${i}; done
uj5u.com熱心網友回復:
由于沒有建議的答案,我決定使用有效的語法切換到 bash(盡管它困擾著我)
for (( i=1 ; i<=${answer} ; i ));
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/438471.html
上一篇:回圈串列R
下一篇:如何在向量c 中找到唯一值
