I have a problem with writing it in bash… I know how it works in C++, but I have trouble implementing it in bash. Here’s what I got:
sum()
{
let minusOne=$1-1
let result=sum $minusOne +$1
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need an exit condition. In bash,
$((...))is arithmetic expansion, and$(...)is command substitution (see the man page).A non-recursive way to write a sum function: