Page 1 of 1

BASH and newLISP variable availability inline code

Posted: Mon Jun 08, 2009 1:56 am
by 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?

Posted: Mon Jun 08, 2009 4:31 am
by TedWalther
Try this:

Code: Select all

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.

Posted: Sun Jul 05, 2009 9:41 am
by ale870
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):

Code: Select all

> (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).

Posted: Wed Jul 08, 2009 6:42 pm
by scottmaccal
Hi ale870,

Thank you for your response. I will give what you suggested at shot.

Posted: Wed Jul 08, 2009 8:42 pm
by newdep
Must it be a read-line? Or you just want to read bash environment values?

Posted: Thu Jul 09, 2009 12:31 am
by scottmaccal
Hi newdep,

I'm wanted to use BASH $USER. Possible?

Posted: Thu Jul 09, 2009 6:59 am
by newdep