1) Should I use $ (()) if I use integers?
As in most cases in programming, "it depends." If you think your code will be used on older unix systems where there is only a bourne shell, then this syntax will not work.
If you are always in a completely modern environment, the $(( ... )) syntax really makes the most sense, since it allows you to use compressed expressions and expressions like C.
Also, as others point out, for any numeric variables inside $(( ... )) you can save the input and eliminate the leading "$" .; -)
2) What is the difference between $ (($ x + 1)) and $ ((x + 1))?
As indicated in the previous paragraph, there is no difference except that you had to type 1 less characters.
Finally, I thank you for your approach to understanding yourself. Your little tests helped you prove these facts for yourself and this is the method that I want more questions about posters here on SO learned to use! ;-).
You are on the right track to understand how to improve your shell knowledge. If you are not aware of the various debugging tools available in the shell, see the third paragraph in Using nohup to execute a very confusing command? , re set -vx and PS4=...
Hope this helps.
source share