BASH and newLISP variable availability inline code

Notices and updates
Post Reply
scottmaccal
Posts: 20
Joined: Fri Mar 28, 2008 2:12 am

BASH and newLISP variable availability inline code

Post 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?
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
Posts: 605
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

Post 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.

ale870
Posts: 297
Joined: Mon Nov 26, 2007 8:01 pm
Location: Italy

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

scottmaccal
Posts: 20
Joined: Fri Mar 28, 2008 2:12 am

Post by scottmaccal »

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
Posts: 2019
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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

scottmaccal
Posts: 20
Joined: Fri Mar 28, 2008 2:12 am

Post by scottmaccal »

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
Posts: 2019
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

-- (define? (Cornflakes))

Post Reply