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?
BASH and newLISP variable availability inline code
-
- Posts: 20
- Joined: Fri Mar 28, 2008 2:12 am
BASH and newLISP variable availability inline code
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
-
- Posts: 608
- Joined: Mon Feb 05, 2007 1:04 am
- Location: Abbotsford, BC
- Contact:
Try this:
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.
Code: Select all
IFS="\n" read MYVAR
export MYVAR
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.
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):
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).
>> (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
--
-
- Posts: 20
- Joined: Fri Mar 28, 2008 2:12 am
-
- Posts: 20
- Joined: Fri Mar 28, 2008 2:12 am
look here..perhpas that helps
http://www.alh.net/newlisp/phpbb/viewto ... bash+shell
http://www.alh.net/newlisp/phpbb/viewto ... bash+shell
-- (define? (Cornflakes))