Page 1 of 1

How to pass variable between scripts

Posted: Tue Jan 27, 2009 6:34 pm
by bokad
Is there any way to pass variables between scripts?
It seems that I can not access variables that are declared global in one script from another script.

Ex.
In script 1:
:global 64kdownload 64000

On the command line:
:environment print
shows: ""64kdownload"=64000

In script 3:
/queue type set "user-download" pcq-rate=$64kdownload

Script three will not run properly. Any ideas?

Re: How to pass variable between scripts

Posted: Wed Jan 28, 2009 3:17 am
by Letni

Re: How to pass variable between scripts

Posted: Wed Jan 28, 2009 10:39 am
by SurferTim
In the scripts that use global variables, but not change them, use this:
:global 64kdownload
/queue type set "user-download" pcq-rate=$64kdownload

Re: How to pass variable between scripts

Posted: Wed Jan 28, 2009 3:21 pm
by janisk
to use global variable you have to declare it - if it is global and already have value - you will be able then access that value.

also note, that script should be in {} signs, or each line will count as separate script.

Re: How to pass variable between scripts

Posted: Wed Jan 28, 2009 4:13 pm
by SurferTim
Pardon me, but I am not sure I understand. What do you mean by "separate script"? I know I use <?php ?> for php, but I saw nothing of the brackets in the examples. I use none in mine unless to group stuff. If I am doing something that may cause me challenges, I would like to know. Maybe a reference or wiki?

BTW I do not use the commands unless assigning them or getting a return value. So it would always be
:local returnval [/command]
I do not use
/command
anywhere.

Re: How to pass variable between scripts

Posted: Thu Nov 29, 2018 4:38 pm
by WojtusW5
Hello, I have similar problem.
I have 2 script
name="test1" source=:global test "12345"; 
name="test2" source=:put $test; 
And I can't display global variable from script

[admin@test] /system script> run test1
[admin@test] /system script> environment print
# NAME VALUE
0 test 12345
[admin@test] /system script> run test2

[admin@test] /system script>

Re: How to pass variable between scripts

Posted: Fri Nov 30, 2018 1:08 am
by eworm
Hello, I have similar problem.
I have 2 script
name="test1" source=:global test "12345"; 
name="test2" source=:put $test; 
And I can't display global variable from script

[admin@test] /system script> run test1
[admin@test] /system script> environment print
# NAME VALUE
0 test 12345
[admin@test] /system script> run test2

[admin@test] /system script>
You have to declare it:
name="test1" source=:global test "12345"; 
name="test2" source=:global test; :put $test;

Re: How to pass variable between scripts

Posted: Fri Nov 30, 2018 8:12 am
by Jotne
To use variable from other script just re-declare the variable without initializing it.

script1
:global previousIP "1.2.3.4"
:put $previousIP
will display 1.2.3.4

script2
:global previousIP
:put $previousIP
will display 1.2.3.4

Re: How to pass variable between scripts

Posted: Fri Nov 30, 2018 9:23 pm
by sebastia
I pass values by using named variables, there is no need for globals here:
ex:
:local rtt [$getRTT target=$target intf=$intfP count=$pcount timeout=$ptimeout]

:global getRTT do={
#:log info "getRTT: target: $target, intf: $intf, count: $count, timeout: $timeout"
...

Re: How to pass variable between scripts

Posted: Fri Nov 30, 2018 10:03 pm
by Jotne
If you read the title
How to pass variable between scripts
You see that global is needed or you can write data to a file.

Re: How to pass variable between scripts

Posted: Sat Dec 01, 2018 9:33 pm
by sebastia
Actually I did see it, but ... if the scripts are related say script1 call on script2, named variables can be used.
If one can't call on the other then that won't fly naturally.

In other way, another option for a developer