user3178889
user3178889

Reputation: 729

Bash script syntax error multiplying a variable with -1

Am trying to mulitply a variable with -1 in bash script

this is the code

u=1
u=$(($u * -1))
if [ $u -eq 1 ]
then
rcolor="white"
#-----30
else
rcolor="#E8EDFF"
fi

Output

script.sh: line 2: syntax error near unexpected token `u=$(($u * 1))'
script.sh: line 2: `u=$(($u * 1))'

Upvotes: 1

Views: 144

Answers (2)

kurumi
kurumi

Reputation: 25609

use bc or other calculator programs.

# echo "10*-1" | bc
-10

Upvotes: 2

ichramm
ichramm

Reputation: 6642

Try changing it to:

u=1
((u *= -1)) # no $
if [ $u -eq 1 ]
then
    rcolor="white"
#-----30
else
    rcolor="#E8EDFF"
fi

Upvotes: 1

Related Questions