How to declare Linux variables by using newLisp

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?

How to declare Linux variables by using newLisp

Postby Darth_Severus » Wed Nov 25, 2015 5:17 pm

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>
Darth_Severus
 
Posts: 18
Joined: Fri Aug 08, 2014 6:08 pm

Re: How to declare Linux variables by using newLisp

Postby oofoe » Wed Nov 25, 2015 6:05 pm

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.
oofoe
 
Posts: 60
Joined: Wed Sep 28, 2005 7:13 pm

Re: How to declare Linux variables by using newLisp

Postby Darth_Severus » Wed Nov 25, 2015 7:37 pm

Ahh, that's it. Thanks!
But, the number needs to be a string as well.

Code: Select all
(env "final_answer" "42")
Darth_Severus
 
Posts: 18
Joined: Fri Aug 08, 2014 6:08 pm


Return to newLISP and the O.S.

Who is online

Users browsing this forum: No registered users and 2 guests

cron