Page 1 of 1

How to declare Linux variables by using newLisp

Posted: Wed Nov 25, 2015 5:17 pm
by Darth_Severus
I'm able to run programs in Linux by using (! <name>) or (exec <name>). But I can't declare variables.

MAIN:/home/usernamedeleted> (! "declare final_answer=42")
sh: 1: declare: not found
32512
MAIN:/home/usernamedeleted> (! "set final_answer=42")
0
MAIN:/home/usernamedeleted> (! "echo $final_answer")

0
MAIN:/home/usernamedeleted> (! "final_answer=42")
0
MAIN:/home/usernamedeleted> (! "echo $final_answer")

0
MAIN:/home/usernamedeleted> (! "export final_answer=42")
0
MAIN:/home/usernamedeleted> (! "echo $final_answer")

0
MAIN:/home/usernamedeleted>

Re: How to declare Linux variables by using newLisp

Posted: Wed Nov 25, 2015 6:05 pm
by oofoe
Hi!

The "!" is a shell command -- it has its own environment every time it's run, which is not saved between invocations.

So, this:

Code: Select all

 (! "set final_answer=42")
is probably working, but when you run this:

Code: Select all

 (! "echo $final_answer")
the previous environment is destroyed in favour of the new one.

You can use the env function for this because it sets the variable in the environment of the currently running process -- newlisp itself:

Code: Select all

(env "final_answer" 42)
(! "echo $final_answer")
Hope this helps!

Re: How to declare Linux variables by using newLisp

Posted: Wed Nov 25, 2015 7:37 pm
by Darth_Severus
Ahh, that's it. Thanks!
But, the number needs to be a string as well.

Code: Select all

(env "final_answer" "42")