Why should I use $[ EXPR ] instead of $(( EXPR ))?

On the paragraph explaining arithmetic expansion, Bash’s user guide uncovers 2 different ways of evaluating an expression, the first one uses $(( EXPRESSION )) and the second one uses $[ EXPRESSION ]. The two ways seem pretty similar as the only difference I have found is:

$[ EXPRESSION ] will only calculate the result of EXPRESSION, and do no tests:

Yet, I am intrigued because the same document recommends using $[ EXPRESSION ] rather than $(( EXPRESSION )).

Wherever possible, Bash users should try to use the syntax with square brackets:

Why would you want that if less tests are being done?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Duplication Question (with answer)

https://stackoverflow.com/questions/2415724/bash-arithmetic-expression-vs-arithmetic-expression

The manpage for bash v3.2.48 says:

[…] The format for arithmetic expansion is:

 $((expression))

The old format $[expression] is deprecated and will be removed in upcoming versions of bash.

So $[…] is old syntax that should not be used anymore

In addition to that answer:

http://manual.cream.org/index.cgi/bash.1#27

Info relating to bash versions:

Here is some info about bash man pages (its hard to find info on what version each one is referring to):

OPs link:

http://www.tldp.org/guides.html
Bash Guide for Beginners
version: 1.11
author: Machtelt Garrels,
last update: Dec 2008

sth (74.6k rep) quoting bash v3.2.48

from https://stackoverflow.com/questions/2415724/bash-arithmetic-expression-vs-arithmetic-expression)

Note: More info about [] vs (()) here: http://lists.gnu.org/archive/html/bug-bash/2012-04/msg00033.html

a link I found:

http://www.gnu.org/software/bash/manual/
last updated August 22, 2012

http://www.gnu.org/software/bash/manual/bash.html#Arithmetic-Expansion


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x