Community discussions

MikroTik App
 
S8T8
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 81
Joined: Thu Sep 15, 2022 7:15 pm

[ ] with space or without?

Thu Mar 02, 2023 9:20 pm

Apologies for the "idiod" question; I saw many scripts with [ /function ] with and without the spaces between [brackets], always used without but all the scripts from MikroTik are with a space in between.
There are cases where space is necessary and other where is not? (Except RegEx)
Thanks
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: [ ] with space or without?  [SOLVED]

Fri Mar 03, 2023 1:51 am

The question is wrong, there is no common rule for everything.

If, on the other hand, you are only talking about code to be executed between [ ], it doesn't matter if you put them there or not.

If you look at my scripts (except in cases that I need to layout the code so it can be read better) I never use them.
[:osfunction parameter]
[/call this function]
[contextfunction parameter]
[$userdefinedfunction parameter]

On other places, you never must put spaces, like on
literally "-1"
do={ 
else={
etc.

Right now I can't come up with examples of where it necessarily takes space (ignoring RegEx)
Just
3 + -2 ; # (for obtain 1)
 not
3+-2 ; # (for obtain 1)
# it work but readabiliy...

# tis do not work at all, give -1 instad of -3
3/ -1
 
S8T8
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 81
Joined: Thu Sep 15, 2022 7:15 pm

Re: [ ] with space or without?

Fri Mar 03, 2023 2:08 am

Was hoping for an answer from you!
The question was easier than you thought, examples:
- /interface ethernet set [ find default-name=ether5 ] VS. /interface ethernet set [find default-name=ether5]
- $[ /system routerboard get model ] VS. $[/system routerboard get model]
- [ :resolve google.com ] VS. [:resolve google.com]
(just few examples pasted from a random search online)

THANKS!
[GRAZIE!]
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: [ ] with space or without?

Fri Mar 03, 2023 2:11 am

I hope you've understood that, apart from when it's necessarily needed, or when it's to be avoided by force, then it's tastes.
I like it without spaces, but sometimes to improve readability, in specific cases, I put them there.
It depends on your taste and how best you read the code.

Who is online

Users browsing this forum: drpioneer and 25 guests