bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Expansions in arithmetic commands and subscripts


From: Thorsten Dahlheimer
Subject: Expansions in arithmetic commands and subscripts
Date: Sat, 2 Jul 2005 18:35:14 +0200

Configuration Information [Automatically generated, do not change]:
Machine: i586
OS: cygwin
Compiler: gcc
Compilation
CFLAGS:  -DPROGRAM='bash.exe' -DCONF_HOSTTYPE='i586' -DCONF_OSTYPE='cygwin' 
-DCONF_MACHTYPE='i586-pc-cygwin' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/
locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -DRECYCLES_PIDS  -I.  -I/ho
me/xxx/bash/bash-3.0 -I/home/xxx/bash/bash-3.0/include -I/home/xxx/bash/bash
-3.0/lib   -O2
uname output: CYGWIN_98-4.10 pcdahl4201 1.5.18s(0.130/4/2) 20050611 15:29:08
i586 unknown unknown Cygwin
Machine Type: i586-pc-cygwin

Bash Version: 3.0
Patch Level: 16
Release Status: release

Description:
According to the documentation, bash should treat the expression inside
a (( ... )) command as if it were double-quoted, and it probably should
treat the expressions in an arithmetic "for" command in the same way for
consistency.
But actually it doesn't do so:  The expressions in arithmetic commands
and arithmetic "for" commands undergo brace expansion, tilde expansion,
and process substitution, and quote removal happens like in unquoted
strings.
The situation is similar with array subscripts, where brace expansion
and tilde expansion are suppressed but process substitution and quote
removal like in unquoted strings occur.  Although the manual doesn't
specify the behaviour in this regard, I think that array subscripts
should also be treated as if they were double-quoted for consistency.

Repeat-By:
$ (( {1+1, '@!#?'} )) && echo 'ok!?'
ok!?

$ # "user" is a valid user name on the system
$ for (( user=5; ~user; user-- )); do echo $user; done
bash: ((: /home/user: syntax error: operand expected (error token is
"/home/user")

$ (( 1<(2+3)*4 )) && echo 'math ok'
bash: ((: 1/proc/self/fd/63*4 : division by 0 (error token is "/self/fd/63*4
")

$ (( '1' + \1 + "1" == 3 )) && echo 'valid!?'
valid!?

$ a=(0 1 2 3)
$ echo ${a[1<(2+3)*4]}
bash: 1/proc/self/fd/63*4: division by 0 (error token is "/self/fd/63*4")
$ echo ${a['1'+\1+"1"]}
3


Regards,
Thorsten Dahlheimer





reply via email to

[Prev in Thread] Current Thread [Next in Thread]