newLISP Fan Club

Forum => newLISP newS => Topic started by: scottmaccal on June 07, 2009, 06:56:21 PM

Title: BASH and newLISP variable availability inline code
Post by: scottmaccal on June 07, 2009, 06:56:21 PM
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?
Title:
Post by: TedWalther on June 07, 2009, 09:31:29 PM
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.
Title:
Post by: ale870 on July 05, 2009, 02:41:00 AM
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).
Title:
Post by: scottmaccal on July 08, 2009, 11:42:09 AM
Hi ale870,



Thank you for your response. I will give what you suggested at shot.
Title:
Post by: newdep on July 08, 2009, 01:42:44 PM
Must it be a read-line? Or you just want to read bash environment values?
Title:
Post by: scottmaccal on July 08, 2009, 05:31:52 PM
Hi newdep,



I'm wanted to use BASH $USER. Possible?
Title:
Post by: newdep on July 08, 2009, 11:59:52 PM
look here..perhpas that helps

//http://www.alh.net/newlisp/phpbb/viewtopic.php?t=2243&start=0&postdays=0&postorder=asc&highlight=bash+shell