How to declare Linux variables by using newLisp

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
Darth_Severus
Posts: 18
Joined: Fri Aug 08, 2014 6:08 pm

How to declare Linux variables by using newLisp

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

oofoe
Posts: 61
Joined: Wed Sep 28, 2005 7:13 pm
Contact:

Re: How to declare Linux variables by using newLisp

Post 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!
Testing can show the presence of bugs, but not their absence.

Darth_Severus
Posts: 18
Joined: Fri Aug 08, 2014 6:08 pm

Re: How to declare Linux variables by using newLisp

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

Locked