I'm new shell scripting and have a quick question about my code. This works:
x=2
y=4
z=6
x=$(( $x-1 ))
y=$(( $y-2 ))
z=$(( $z-3 ))
echo $x $y $z
$ script.sh
1 2 3
And this works:
n=2,4,6
IFS=$',' read x y z <<< $n
echo $x $y $z
$ script.sh
2 4 6
But this results in a syntax error:
n=2,4,6
IFS=$',' read x y z <<< $n
x=$(( $x-1 ))
y=$(( $y-2 ))
z=$(( $z-3 ))
echo $x $y $z
$ script.sh
syntax error in expression (error token is "4 6-1 ")
2 4 6 -2 -3
Could someone please explain why this doesn't work and what the syntax error means? Thanks!