How to declare Linux variables by using newLisp

Started by Darth_Severus, November 25, 2015, 09:17:38 AM

Previous topic - Next topic

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>

oofoe

#1
Hi!



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



So, this: (! "set final_answer=42")
is probably working, but when you run this: (! "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:

(env "final_answer" 42)
(! "echo $final_answer")


Hope this helps!
Testing can show the presence of bugs, but not their absence.

Darth_Severus

#2
Ahh, that's it. Thanks!

But, the number needs to be a string as well.


(env "final_answer" "42")