2

From this post I learned that : can be used to get the side effects of a parameter expansion. I stumbled upon this code which uses a parameter expansion that looks new to me:

$ R=32; : $[R--]; echo $R
31

Here : $[R--] seems to be equivalent to ((R--)). What is $[]? And is it documented in man bash(1)? I couldn't find it on the man pages.

builder-7000
  • 202
  • 1
  • 9
  • Thanks that answers my question. Then this should be a duplicate – builder-7000 Nov 11 '19 at 18:46
  • 2
    See also [What does a dollar sign followed by a square bracket mean in bash?](https://unix.stackexchange.com/questions/209833/what-does-a-dollar-sign-followed-by-a-square-bracket-mean-in-bash) – steeldriver Nov 11 '19 at 18:48
  • 1
    @JeffSchaller, with that title, that question is rather misleading... – ilkkachu Nov 11 '19 at 18:49
  • 1
    searching for questions with symbols is hard; fortunately, steeldriver's comment text had enough for me to go on, and found that Q/A – Jeff Schaller Nov 11 '19 at 18:54
  • @JeffSchaller, I know, the search sucks for them. I just hoped there would have been a better one to point to, and didn't see that other link when typing. – ilkkachu Nov 11 '19 at 19:09
  • @ilkkachu if you do happen to find any more, please ping me here and I'd be happy to add them! – Jeff Schaller Nov 11 '19 at 19:11
  • @JeffSchaller, well, I edited the duplicate list... – ilkkachu Nov 11 '19 at 19:17
  • I tried to look through the old docs and thought I saw a mention that the `$[...]` would be removed in a future version, but now I can't find it. (@steeldriver, did you quote that from somewhere in a comment?) It still seems to work in Bash 5.0, so apparently we're not far enough in the future yet. :) – ilkkachu Nov 11 '19 at 19:19
  • Relating https://unix.stackexchange.com/questions/66977/difference-between-two-types-of-shell-arithmetic – Jeff Schaller Nov 11 '19 at 19:25
  • @ikkachu I found it in `man bash` (version 4.4.20(1)-release) under `Arithmetic Expansion` – steeldriver Nov 11 '19 at 19:41
  • @steeldriver, ah right. It wasn't in the older versions. Thanks. – ilkkachu Nov 11 '19 at 20:09

0 Answers0