Hi everyone,
I read some shell script code,then I have some issue.
the following code.
let "t1 = ((5 + 3, 7 - 1, 15 - 4))"
echo "t1 = $t1"
t1=11
Here t1 is set to the result of the last operation.why?
Hi everyone,
I read some shell script code,then I have some issue.
the following code.
let "t1 = ((5 + 3, 7 - 1, 15 - 4))"
echo "t1 = $t1"
t1=11
Here t1 is set to the result of the last operation.why?
Arithmetic expressions in modern shells use the same syntax as is used in the C programming language. And in C, the value of a numeric expression using the comma operator is the value of the last subexpression, in your case 15 - 4 .
it's just like
((t1=5+3)) # t1 = 8
((t1=7-1)) # t1 = 6
((t1=15-4)) # t1 = 11
If you have a "modern" shell (like bash), the "let" statement is obsolete.
Thanks,
I understand your meaning,I use shell of fedora 11 ,I have already tested this issue in my system,and as your result.