Bash 'let' command in scripts
by dedec0 from LinuxQuestions.org on (#5DF7A)
I have read the bash man page about let command:
Code:let arg [arg ...]
Each arg is an arithmetic expression
to be evaluated (see ARITHMETIC EVALU
ATION above). If the last arg evalu
ates to 0, let returns 1; 0 is
returned otherwise.But on this script i am reading, it is written this:
Code:function push_pieces {
case $4 in
"up")
let "first=$2*$board_size+$1"
let "second=($2+$3)*$board_size+$1"
;;
"down")
let "first=(index_max-$2)*$board_size+$1"
let "second=(index_max-$2-$3)*$board_size+$1"
;;
"left")
let "first=$1*$board_size+$2"
let "second=$1*$board_size+($2+$3)"
;;
"right")
let "first=$1*$board_size+(index_max-$2)"
let "second=$1*$board_size+(index_max-$2-$3)"
;;
esac
# [...]
}In each case possibility, are the variables $first and $second being evaluated with a mathematical expression that follows them? It is very strange because "$board_size" has a dolar sign, "index_max" does not, and "first" and "second" also do not.


Code:let arg [arg ...]
Each arg is an arithmetic expression
to be evaluated (see ARITHMETIC EVALU
ATION above). If the last arg evalu
ates to 0, let returns 1; 0 is
returned otherwise.But on this script i am reading, it is written this:
Code:function push_pieces {
case $4 in
"up")
let "first=$2*$board_size+$1"
let "second=($2+$3)*$board_size+$1"
;;
"down")
let "first=(index_max-$2)*$board_size+$1"
let "second=(index_max-$2-$3)*$board_size+$1"
;;
"left")
let "first=$1*$board_size+$2"
let "second=$1*$board_size+($2+$3)"
;;
"right")
let "first=$1*$board_size+(index_max-$2)"
let "second=$1*$board_size+(index_max-$2-$3)"
;;
esac
# [...]
}In each case possibility, are the variables $first and $second being evaluated with a mathematical expression that follows them? It is very strange because "$board_size" has a dolar sign, "index_max" does not, and "first" and "second" also do not.