I think the “:” may be a special character in regex. Plus, you’d be searching for all CONTAINING, not STARTING, so try:
:put [find where comment~“^BP:”]or if that doesn’t work, try to make it more explicit, like:
:put [find where comment~“^BP:.*$”]
If its in a script the $ needs to be escaped also.
:put [find where comment~“^BP:.*$”] .. I’m not sure if the : needs to be escaped. You’ll just have to try it.
.(dot) *****(star) $(dollar) all are special symbols where (dot) - one symbol; (star) - previous symbol repeated none or any times; (dollar) - end of string.
if you escape them, then script will look for the symbol inside the string and script will not work.
I can now run this fine from the terminal, but when pasting my code into a script , I have a problem with the Tilde character directly after the where statement causing problems.
comment~“^BP:.*$”]
^-This character gets flagged up when running /sys scr print as being bad and stops the script.
I don’t think you actually need the where in the script. Show us the full script. But for example the below code works fine.
:foreach i in [/interface ethernet find comment=~“^BP:.*$”] do={
:put “test”
}
Escaping $ works fine. But I must be missing something since escaping a dot like . gives me a syntax error.
I’d like to prevent script from potentially finding files that have longer extensions:
{
:local mm "01"
:local yyyy 2021
:foreach FILE in=[/file find name~"^disk1/backups/$yyyy-$mm/.+\.txt\$" ] do={
:local name [/file get $FILE name];
:put $name;
}
}