BASH and newLISP variable availability inline code

Started by scottmaccal, June 07, 2009, 06:56:21 PM

Previous topic - Next topic

scottmaccal

Hi all,



I was wondering if it was possible to read a variable with read-line and make that variable available for a newLISP code or vice versa?
Whether gods exist or not, there is no way to get absolute certainty about ethics. Without absolute certainty, what do we do? We do the best we can. --Richard Stallman

TedWalther

#1
Try this:



IFS="n" read MYVAR
export MYVAR


Type in your line of text and hit enter.  read will store the entire line of text in $MYVAR, using export will make it available to newlisp or whichever other program you start in the shell session.



In newLISP, use (getenv ...) to retrieve  the bash variable.



I don't know of any way to make newLISP variables available to bash, assuming that bash you mean is the one that invoked newLISP in the first place.  If you are starting bash up from inside newLISP, it may be possible I don't have time to research it right now though.
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence.  Nine months later, they left with a baby named newLISP.  The women of the ivory towers wept and wailed.  \"Abomination!\" they cried.

ale870

#2
Note: to read or setup an environment variable from newLisp you need to use (env).



>> (env)

Retrieve a complete list of all env variabiles.



>> (env myVar)

Retrieve a specified env variable.



>> (env myVar newValue)

Will set a new value for the specified env variabile.



Generally speaking, an environment variable will be "propagated" only to the child environments. So if you setup a new env value, you can use that value only in the new executed shell program (for example using (!) or (exec)). See this example (linux):



> (env "CHECK_DIR" "/bin")(! "ls -l $CHECK_DIR")
true
total 6432
-rwxr-xr-x 1 root root    5428 2008-10-29 20:15 archdetect
-rwxr-xr-x 1 root root    1062 2008-05-20 00:15 autopartition
-rwxr-xr-x 1 root root    8635 2008-06-20 14:21 autopartition-loop
-rwxr-xr-x 1 root root  725136 2008-05-12 20:48 bash
-rwxr-xr-x 1 root root   30140 2008-06-23 10:02 bunzip2



As you can see, I setup CHECK_DIR environment variable, and the next shell command, executed from newLisp, can read my env variable (since "ls" is a child of my process).
--

scottmaccal

#3
Hi ale870,



Thank you for your response. I will give what you suggested at shot.
Whether gods exist or not, there is no way to get absolute certainty about ethics. Without absolute certainty, what do we do? We do the best we can. --Richard Stallman

newdep

#4
Must it be a read-line? Or you just want to read bash environment values?
-- (define? (Cornflakes))

scottmaccal

#5
Hi newdep,



I'm wanted to use BASH $USER. Possible?
Whether gods exist or not, there is no way to get absolute certainty about ethics. Without absolute certainty, what do we do? We do the best we can. --Richard Stallman

newdep

#6
look here..perhpas that helps

http://www.alh.net/newlisp/phpbb/viewtopic.php?t=2243&start=0&postdays=0&postorder=asc&highlight=bash+shell">//http://www.alh.net/newlisp/phpbb/viewtopic.php?t=2243&start=0&postdays=0&postorder=asc&highlight=bash+shell
-- (define? (Cornflakes))