22
rated 0 times
[
22]
[
0]
/ answers: 1 / hits: 9781
/ 2 Years ago, tue, august 2, 2022, 6:17:31
In below function with 9 arguments:
SUM() {
echo "The sum is $(($1+$2+$3+$4+$5+$6+$7+$8+$9))"
}
I want to make the second arguments to the next(3..9) become a optional arguments.
When I call the function with 2 arguments I get error:
SUM 3 8
bash: 3+8+++++++: syntax error: operand expected (error token is "+")
Note BOLD: first argument and second argument are force arguments and not optional for function. I only want second arguments to the next is optional and when I call the function less than 2 args the function must return no result.
More From » bash