bash - How to handle negative arguements in a fibonacci series using bash script in linux
问题描述
How can I add a condition that will deal with a negative number input for my Fibonacci series in bash script? This is my code:
clear
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: Program that finds the fibonacci series"
echo "Options:"
echo "-h shows this help information "
echo "-lt the value on the left is less than the value on the right"
echo "expr evaluates a given expression and displays its corresponding output "
exit 1
fi
echo 'This program will find the Fibonnacci Series'
echo "Enter the number of terms you want to be generated"
read n
f1=0
f2=1
i=2
echo "The following is the Fibonacci Series upto $n term:"
echo $f1
echo $f2
while [ $i -lt $n ]
do
i=`expr $i + 1`
f3=`expr $f1 + $f2
echo $f3
f1=$f2
f2=$f3
done
解决方案
推荐阅读
- javascript - iframe 悬停时滚动父窗口
- r - 在 U-SQL 中执行 R
- excel - 当单元格在单元格范围内有值时插入新行
- android - Android - 无法解决:cardview-v7
- google-analytics-api - 如何在 api explorer 中使用 Google Analytics API v3 > analytics.management.uploads.uploadData 方法
- angular - 如何在angular2中的路由期间保存数据
- azure - Azure 流分析筛选 IOT 中心输入
- php - 在 jQuery 模式中显示成功消息
- html - 链接的div中的文本,我也想悬停文本
- haskell - 对类图数据结构的建议