Community discussions

MikroTik App
 
greggio
just joined
Topic Author
Posts: 12
Joined: Fri Feb 16, 2024 8:24 pm

Saving file package version in a variable

Tue Apr 09, 2024 2:36 pm

Hi guys!

I'm trying to create obtain the package version of one npk file and store it into a variable, but in every way i tried, my variable stills empty.
:local packageVersion (/file get (find ".npk") package-version)
:put $packageVersion


Can somebody help me with a solution please?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12025
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Saving file package version in a variable  [SOLVED]

Tue Apr 09, 2024 5:28 pm

the file is called .npk?
why you use () ???
 
greggio
just joined
Topic Author
Posts: 12
Joined: Fri Feb 16, 2024 8:24 pm

Re: Saving file package version in a variable

Tue Apr 09, 2024 6:32 pm

the file is called .npk?
why you use () ???
No the file is named as a mikrotik firmware, something like "routeros-arm-6.49.10.npk". I noticed this after posting, i changed to:
:local packageVersion [/file get [find type="package"] package-version]
I didn't even think about the use (), i'm kind new to scripting, thanks for the hint!
It's working with the script above. Thanks man!
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3567
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Saving file package version in a variable

Wed Apr 10, 2024 5:44 pm

I didn't even think about the use (), i'm kind new to scripting, thanks for the hint!
If you know Linux/UNIX, the [] are similar to `` backtick to run a command and replace result in-place.
 
User avatar
patrikg
Member Candidate
Member Candidate
Posts: 264
Joined: Thu Feb 07, 2013 6:38 pm
Location: Stockholm, Sweden

Re: Saving file package version in a variable

Wed Apr 10, 2024 5:56 pm

I didn't even think about the use (), i'm kind new to scripting, thanks for the hint!
If you know Linux/UNIX, the [] are similar to `` backtick to run a command and replace result in-place.
Yes and the new way of doing this in UNIX/Linux, not using back tics chars. is like this.
Use dollar sign and regular parentheses.
$(cat /etc/passwd)
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3567
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Saving file package version in a variable

Wed Apr 10, 2024 7:18 pm

It's likely better thinking of the RouterOS CLI in terms of a REPL for a programming language, than ANY UNIX shell.
It's thinking CLI is more like Linux/UNIX is where the trouble starts ;)

FWIW, I'm not sure $() is newer than ``. The $() is more for variable assignment IMO, while backtick works anywhere.
Yes and the new way of doing this in UNIX/Linux, not using back tics chars. is like this.
Use dollar sign and regular parentheses.
$(cat /etc/passwd)

Who is online

Users browsing this forum: No registered users and 8 guests