help-bash
[Top][All Lists]
Advanced

[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: Chris F.A. Johnson
Subject: Re: Is there a way to get the output of a function without an extra bash process?
Date: Sun, 10 May 2020 17:36:17 -0400 (EDT)
User-agent: Alpine 2.21 (DEB 202 2017-01-01)

On Sun, 10 May 2020, Peng Yu wrote:

Hi,

$(fun) by default will always use a new bash process. This is wasteful
in certain cases. In there a way to use the existing bash process
(without using a temp file)? Thanks.

$ cat ./main2.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

set -v
echo "$BASHPID"
function f {
        echo "$BASHPID"
}
echo "$(f)"
$ ./main2.sh
echo "$BASHPID"
32056
function f {
        echo "$BASHPID"
}
echo "$(f)"
32057

f()
{
 printf -v pid %s "$BASHPID"
}


--
   Chris F.A. Johnson                         <http://cfajohnson.com/>
   =========================== Author: ===============================
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
   Pro Bash Programming: Scripting the GNU/Linux shell (2009, Apress)



reply via email to

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