When I do:
let "a = $a % 5"
my output is:
let: a = % 5: syntax error: operand expected (error token is "% 5")
Why I obtain this error? How can I correct this?
bash should also know (( )) arythmetic as an equivalent for the let command:
(( a=a%5 ))
(( a=a % 5 ))
And there's really no need for the $s, "let" knows about the value of variables or tokens without the need for variable substitution by the shell...
let a=a%5
let a=$a%5
let a=${a}%5
let a='a % 5'
let a="a % 5"
let a="$a % 5"
let a="${a} % 5"
If you do want to use "let" and $s and spaces for clarity, you also have to use double quotes or the shell won't substitute the variable values. (Variable substitution doesn't occur inside single quotes)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.