Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: unexpected unmodified variable
On Thu, Oct 6, 2022 at 2:59 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote
>
> On 2022-10-06 12:28, Peter Stephenson wrote:
>
> > Returning stuff in a sane way is a real weakness in shells.
Shrug; shells were originally designed to facilitate text processing
by small independent single-purpose applications. Everything else is
a bolt-on.
> I ended up sending the output to a bleeding file and
> then rereading that. There otta be a better way.
if you're only dealing with numbers, then the bolted-on math-function
capability can do "real" return values with locally-visible
side-effects.
func2 ()
{
(( count=2 )) # math op defines return value
echo set by func2: $count
}
func1 ()
{
local count=1
func2
echo got from func2: $count
count=1
var=$(( func2() )) # note parens
echo seen from func1: $count
echo var is: $var # now integer not text
}
functions -M func2
Messages sorted by:
Reverse Date,
Date,
Thread,
Author