bug-bash
[Top][All Lists]
Advanced

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

Re: Bug or feature: Why does Bash's "printf" define global variables?


From: Chet Ramey
Subject: Re: Bug or feature: Why does Bash's "printf" define global variables?
Date: Mon, 04 Aug 2014 09:55:14 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

On 8/3/14, 11:02 AM, Tim Friske wrote:
> Hi,
> 
> my assumption was that Bash's "printf" builtin implicitly defines a local
> variable when used inside a function like so:
> 
>     function foobar { printf -v foo bar; }
>     foobar
>     declare -p foo
>     # Prints "bar" from the global "foo" variable.

Bash creates local variables when local/declare/typeset are used to declare
a variable within a function.  printf -v var [opts] format [args] works
more like

v=$(printf [opts] format [args])

without the subshell or any of the special handling command substitution
receives.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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