Re: Modifying the environment variables of a parent process
Hi,
Gianfranco Costamagna wrote:
> first I guess this isn't the right place, but well, the damage is done :)
Maybe we should move to debian-user@lists.debian.org
if we discuss on. :))
Markhazy wrote:
> > the desired effect
> > user@user:-$ cdiv -1 5 6 0
> > -0.16667 + j0.8333
> > user@user:-$ echo $AC
> > -0.16667
> > user@user:-$ echo $ACIM
> > 0.8333
Parent environment is out of reach. At least by tradition.
Shell functions can set their caller's variables.
How about this one decoding the output line of cdiv:
my_cdiv () {
read AC plus_dummy ACIM <<EOT
$(cdiv "$@")
EOT
# Remove the leading "j" from the imaginary output
ACIM=$(echo "$ACIM" | sed -e 's/^j//')
}
You'd write the function into a script file and at
intialization time execute it inline (thus the leading '.')
in the dialog shell:
. my_cdiv_initializer.sh
Not having "cdiv", i tested with
$(echo "$@")
instead, and gave the desired cdiv result as argument
$ my_cdiv "-0.16667 + j0.8333"
$ echo $AC
-0.16667
$ echo $ACIM
0.8333
This depends much on the output format of cdiv being
uniform. Abbreviated output like
j0.8333
or
-0.16667
would need more brains inside the shell function.
Have a nice day :)
Thomas
Reply to: