bug-bash
[Top][All Lists]
Advanced

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

local variable escapes into trap


From: Akim Demaille
Subject: local variable escapes into trap
Date: Tue, 29 Dec 2009 10:19:04 +0100

Hi!

On the following script, the local variable $name of bar() hides the global $name when entering the trap. I have observed that with several versions of Bash, including

GNU bash, version 4.0.33(1)-release (i486-pc-linux-gnu)


FWIW, Zsh and Dash behave as I expected.

% cat /tmp/foo.sh
#! /bin/sh

trap 'echo "trap: name=$name"' 0

name=main

bar ()
{
    local name=bar
    exit 0
}

bar
% bash /tmp/foo.sh
trap: name=bar

Cheers.




reply via email to

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