From 4585375ae8c891242640fc9628e1475c78925fdf Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 22 Jan 2019 13:57:16 +0200 Subject: Add note to Bash guide on arithmetic expansion ( $(( )) ) --- doc/bash-style.cli | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/bash-style.cli b/doc/bash-style.cli index f81479b..9e90e8a 100644 --- a/doc/bash-style.cli +++ b/doc/bash-style.cli @@ -224,6 +224,19 @@ along these lines: rm -f \"$dir/$name\".* \ +\N|One exception to this quoting rule is arithmetic expansion (\c{$((\ ))}): +Bash treats it as if it was double-quoted and, as a result, any inner quoting +is treated literally. For example: + +\ +z=$(($x + $y)) # Ok. +z=$((\"$x\" + \"$y\")) # Error. +z=$(($x + $(echo \"$y\"))) # Ok. +\ + +| + + If you have multiple values (e.g., program arguments) that may contain spaces, don't try to handle them with quoting and use arrays instead. Here is a typical example of a space-aware argument handling: -- cgit v1.1