[Top][All Lists]

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

Re: Is there a way to get the output of a function without an extra bash

From: Greg Wooledge
Subject: Re: Is there a way to get the output of a function without an extra bash process?
Date: Mon, 11 May 2020 07:49:19 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Sun, May 10, 2020 at 05:36:17PM -0400, Chris F.A. Johnson wrote:
> f()
> {
>  printf -v pid %s "$BASHPID"
> }

What a fancy way of writing

f() { pid=$BASHPID; }

Of course, as soon as you've written this, Peng Yu will claim that it
is a wrong answer, because they lied about the original question, and
they do not actually want the value of $BASHPID.  They will claim that
this was "just an example" (or words to that effect), and that you were
supposed to read their mind and understand the real question behind
their words.

Also, that Subject: header looks like it might be a clue to the question.
Most of us know that you do NOT put your question in the Subject: header,
because people don't read it, and/or it gets mangled as the thread
progresses.  But, I don't think Peng Yu knows this.  I don't think they
know much at all.

P.S. <> explains some of the
available hacks for returning values from functions to their callers.

If you don't like any of those options, then stop writing programs in
bash (and sh).  Use a real programming language, where functions can
return values.

reply via email to

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