Looking for an easy way to make a random number, i came across a web page that used the follow snip of code
echo $[ ( $RANDOM % $DIE_SIDES ) + 1 ]
What is the purpose of the $[. Googling did not reveal the answer I seek. Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
$[expression]construct is used for arithmetic;$[1+1], for example, returns 2. You can also say$((expression))orexpr 1 + 1. Theexprcommand version is old-school and should work in any shell, the$[expression]and$((expression))versions work in bash but I’m not sure if they’re covered by POSIX.Update: The
$[expression]form is a bash extension, the$((expression))form is specified for the POSIX shell.