bug-bash
[Top][All Lists]
Advanced

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

weird behaviour of ((count++)) when using , , to change to lower case


From: Andrew Benton
Subject: weird behaviour of ((count++)) when using , , to change to lower case
Date: Sun, 01 Aug 2010 12:06:56 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:2.0b3pre) Gecko/20100725 Shredder/3.2a1pre

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu' 
-DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -g -O2
uname output: Linux eccles 2.6.35-rc6 #1 SMP Fri Jul 23 11:52:29 BST 2010 
x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-unknown-linux-gnu

Bash Version: 4.1
Patch Level: 2
Release Status: release

Description:
Incrementing a variable with ((count++)), which should access the value 
in the variable and then increment it by 1 has some strange behaviour. 
In some situations it seems to increment the variable before accessing 
it, and in others it increments it by 2

Repeat-By:
Make an array to work with:

andy:~$ days=({Mon,Tues,Wednes,Thurs,Fri,Satur,Sun}day)
andy:~$ echo ${days[@]}
Monday Tuesday Wednesday Thursday Friday Saturday Sunday

So far, so good. Now try to access the array by stepping through it with
((count++))

andy:~$ count=0
andy:~$ echo "${days[$((count++))]}, ${days[$((count++))]}, 
${days[$((count++))]}"
Monday, Tuesday, Wednesday

Also good. Now try converting it to lower case with ,,

andy:~$ count=0
andy:~$ echo "${days[${count}],,}, ${days[$((count++))],,}, 
${days[$((count++))],,}"
monday, tuesday, thursday

What happened to wednesday?

Andy



reply via email to

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