Bug with local variable

2010-09-14 Thread Mario Jungwirth
Hello

I found a bug with local variable. 
My source (The directory dosn't exists!!!)

function test()
{
local myreturn=$(ls -la /directoryNotExists)
echo "return value=$?"
}

The "return value" is now 0!
If i remove the "local" the "return value" is 2 <-- this is correct.

Is this a bug or do I something wrong?

Mfg
Mario Jungwirth




Re: Bug with local variable

2010-09-14 Thread Pierre Gaston
On Tue, Sep 14, 2010 at 10:27 AM, Mario Jungwirth
 wrote:
> Hello
>
> I found a bug with local variable.
> My source (The directory dosn't exists!!!)
>
> function test()
> {
>    local myreturn=$(ls -la /directoryNotExists)
>    echo "return value=$?"
> }
>
> The "return value" is now 0!
> If i remove the "local" the "return value" is 2 <-- this is correct.
>
> Is this a bug or do I something wrong?
>
> Mfg
> Mario Jungwirth
>
>
>
It has been discussed several times here, see for instance:

http://lists.gnu.org/archive/html/bug-bash/2010-03/msg7.html

Keeping local declaration and assignment on separate lines avoid
little troubles like this:
local myreturn
myreturn=$(command)



Assignment to integer variable

2010-09-14 Thread Diego Augusto Molina

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: x86_64-pc-linux-gnu-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
-DSTANDARD_UTILS_PATH='/bin:/usr/bin:/sbin:/usr/sbin'
-DSYS_BASHRC='/etc/bash/bashrc'
-DSYS_BASH_LOGOUT='/etc/bash/bash_logout' -DNON_INTERACTIVE_LOGIN_SHELLS
-DSSH_SOURCE_BASHRC -O2 -pipe
uname output: Linux diegom 2.6.34-gentoo-r1 #4 SMP Thu Jul 22 21:06:07
ART 2010 x86_64 Intel(R) Pentium(R) Dual CPU T2330 @ 1.60GHz
GenuineIntel GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.0
Patch Level: 37
Release Status: release

Description:
BASH complains when asigning some (didn't try all of them)
non-ASCII characters to a variable with the integer attribute. Tried
with vocal letters with an acute accent, grave accent, circumflex
accent, 'Ñ', 'ñ', 'ç', 'Ç', and some more I can't remember by now. Hoped
it would just do nothing, as happens when asigning anything that is not
a number to a variable of this kind.
  Thank you for BASH.

Repeat-By:
declare -i variable
variable='á'

-- 

Diego Augusto Molina
diegoaugustomol...@gmail.com



trap 'echo "trap exit on ${LINENO}"' EXIT -> wrong linenumber

2010-09-14 Thread Jochen Dekeyser
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-redhat-linux-gnu'
-DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale'
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include
-I./lib  -D_GNU_SOURCE -DRECYCLES_PIDS  -O2 -g -pipe -Wall
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m64 -mtune=generic
uname output: Linux phanes 2.6.34.6-54.fc13.x86_64 #1 SMP Sun Sep 5
17:16:27 UTC 2010 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-redhat-linux-gnu

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

Description:
Run this script:

#!/bin/bash

trap 'echo "trap error on ${LINENO}"' ERR
trap 'echo "trap exit on ${LINENO}"' EXIT

/bin/false

exit 0

You should get (and this is also the result you get in Bash 3.2):

trap error on 6
trap exit on 8

But you get:

trap error on 6
trap exit on 1


Repeat-By:
Run the script! (See the description-section)



Re: Assignment to integer variable

2010-09-14 Thread Pierre Gaston
On Tue, Sep 14, 2010 at 4:42 PM, Diego Augusto Molina
 wrote:
>
> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: x86_64-pc-linux-gnu-gcc
> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
> -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
> -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib
> -DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
> -DSTANDARD_UTILS_PATH='/bin:/usr/bin:/sbin:/usr/sbin'
> -DSYS_BASHRC='/etc/bash/bashrc'
> -DSYS_BASH_LOGOUT='/etc/bash/bash_logout' -DNON_INTERACTIVE_LOGIN_SHELLS
> -DSSH_SOURCE_BASHRC -O2 -pipe
> uname output: Linux diegom 2.6.34-gentoo-r1 #4 SMP Thu Jul 22 21:06:07
> ART 2010 x86_64 Intel(R) Pentium(R) Dual CPU T2330 @ 1.60GHz
> GenuineIntel GNU/Linux
> Machine Type: x86_64-pc-linux-gnu
>
> Bash Version: 4.0
> Patch Level: 37
> Release Status: release
>
> Description:
>        BASH complains when asigning some (didn't try all of them)
> non-ASCII characters to a variable with the integer attribute. Tried
> with vocal letters with an acute accent, grave accent, circumflex
> accent, 'Ñ', 'ñ', 'ç', 'Ç', and some more I can't remember by now. Hoped
> it would just do nothing, as happens when asigning anything that is not
> a number to a variable of this kind.
>  Thank you for BASH.
>
> Repeat-By:
>        declare -i variable
>        variable='á'
>
> --
>
> Diego Augusto Molina
> diegoaugustomol...@gmail.com
>

It doesn't complain only when you assign something that is a valid
variable name:
ie
declare -i var
var=foo # is fine foo is a variable an empty/unset variable is evaluated as 0
var="a b" # error

just for fun try:
foo=1+1+1
var=foo
echo "$foo $var"