help-bash
[Top][All Lists]
Advanced

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

Re: sub-process changing value available to parent process?


From: Sylvain Viart
Subject: Re: sub-process changing value available to parent process?
Date: Wed, 8 Apr 2020 08:24:05 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0

Hi Greg,

Thanks for your contribution. I feel it a bit violent, and for no reason
that I can understand.
Never mind, it probably reveal that my question is still too confuse, sorry.

I restart with a completed background :

I'm exploring bash possibilities to return multiples variables from a
child process to a parent script.
Or it could also be expressed: allowing a child process to modify part
of its parent environment.
I know it can be accomplished by eval() but I'm exploring alternative
way to pass complex result, while keeping it safe, and efficient.
Complex result, may include nested structure key pointing to array or
some intermediate text splitable format.
The eval may be required at the final but through a filtered / safe
assignment output.
I'm opening the possible alternatives by asking the question, if
something else could achieve the same goal?
Especially when the parent process could run as root (because of
administrative sysadmin task script), and the child process is a
opensource compiled binary that someone else has developed.

I tested:

eval "$(child --arg --more -v -p filenam)"

# the companion is calling: eval "$(child +processed args)"
source child_companion.sh --some-arg  --more  -v -p filename

I discovered that I could also embedded the companion source in the
child itself if I want:

source <(child --produce-bash --some-arg  --more  -v -p filename)

I also tested an IPC with trap and signaling the parent that something
is ready for reading, the parent passing the /dev/shm temporary file
where the resources should be written, see my post:
https://lists.gnu.org/archive/html/help-bash/2020-04/msg00003.html

./child.sh $$ $TMP_VAL

I also tested to output complex data as JSON

JSON=$(./child --json --more "$@")
export JSON

and getting back value from the program itself knowing the environment
variable to read, but it's a bit heavy and slow:

some_var=$(./child get  mykey)
some_array=( $(./child get  mykey_array) )

So I'm extending my reflection writing this mailing list, I may discover
if there is any other alternative?
I may realize after the exploration that only eval can get it done, of
course. ;-)

>> set -euo pipefail
> As soon as I saw this, I decided to delete the entire thread.  This
> is not salvageable.  This is a sign of grave incompetence and/or
> ignorance.  Combined with "I know the answer is eval but I want a
> different answer", it points to intransigent stubbornness.

Sorry I probably miss some references here.
Open source development taught me to keep learning from my mistakes and
sharing. :-)
So I will share an Isaac Asimov quote:

“Never let your sense of morals prevent you from doing what is right.”
source: https://www.goodreads.com/work/quotes/1783981-foundation

Regards,
Sylvain.

-- 
Sylvain Viart - GNU/Linux Sysadmin/Developer/DevOps - France





reply via email to

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