weird behaviour of ((count++)) when using , , to change to lower case
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 ${da...@]} 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
Re: weird behaviour of ((count++)) when using , , to change to lower case
Am 01.08.2010 13:06, schrieb Andrew Benton: 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? I'd rather expect this to print monday, monday, tuesday, since you left out the ++ in the first term. I think the problem is that the ,, operator causes each expression to be evaluated twice. That would explain this behaviour, and it's a bug IMHO. Regards, Bernd -- Bernd Eggink http://sudrala.de
Re: weird behaviour of ((count++)) when using , , to change to lower case
If I do the echo line twice, I get a segfault in both Bash 4.0.33(1)-release and 4.1.0(1)-release. And you're right about being evaluated twice. On Sun, Aug 1, 2010 at 3:59 PM, Bernd Eggink mono...@sudrala.de wrote: Am 01.08.2010 13:06, schrieb Andrew Benton: 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? I'd rather expect this to print monday, monday, tuesday, since you left out the ++ in the first term. I think the problem is that the ,, operator causes each expression to be evaluated twice. That would explain this behaviour, and it's a bug IMHO. Regards, Bernd -- Bernd Eggink http://sudrala.de
basic pattern match Question...newbie doesn't understand (!...@#$@$)
I have: w=/home/law/bin/package: line 5: type: xx: not found The =~ operator is suppose to use the RH Expr as a ext.-regex. So why doesn't this match and print not found? if [[ $w =~ .*not found.* ]]; then echo not found; fi It prints nothing. Seems like such a basic concept. Sorry, this newbie needs help on such trivial matters. :-( echo $BASH_VERSION 4.0.35(1)-release
RFE? request for an undefined attribute for functions
I had(have) several functions that I don't use on a regular basis (rarely), that I had put into a subdir func_lib under my local-definitions directory. This came from ksh, which allows you to define functions with an undef attribute, and at runtime, the first time these functions were referenced, Is this something that might have been considered for bash? It seems like it could have some usefulness?
Re: basic pattern match Question...newbie doesn't understand (!...@#$@$)
On Sun, 1 Aug 2010, Linda Walsh wrote: I have: w=/home/law/bin/package: line 5: type: xx: not found The =~ operator is suppose to use the RH Expr as a ext.-regex. So why doesn't this match and print not found? if [[ $w =~ .*not found.* ]]; then echo not found; fi It prints nothing. Seems like such a basic concept. Sorry, this newbie needs help on such trivial matters. :-( When quoted, the right-hand argument is matched as a string, not an expression. -- Chris F.A. Johnson, http://cfajohnson.com Author: Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)