Non-working bash arithmetic expression
Hello,
It seems that npf scripts don't support bash arithmetic expression. Not only does it show syntax errors, but it also seems to reset the content of variables to "None". Is this an expected behaviour ?
Example of non-working script:
# addition.npf
%info
Simple addition
%script
i=0
i=$(($i + 1))
echo $i
Output:
$ npf-run --test addition.npf
cluster/localhost.node could not be found, we will connect to localhost with SSH using default parameters
Starting tests
[Local] Running test test.npf...
Simple addition
Executing init scripts...
[run 1/3 for test 1/1]
$i + 1
SyntaxError: invalid syntax (<unknown>, line 1)
[0] None
Could not find any results ! Something probably went wrong, check the output :
[run 2/3 for test 1/1]
$i + 1
SyntaxError: invalid syntax (<unknown>, line 1)
[0] None
Could not find any results ! Something probably went wrong, check the output :
[run 3/3 for test 1/1]
$i + 1
SyntaxError: invalid syntax (<unknown>, line 1)
[0] None
Could not find any results ! Something probably went wrong, check the output :
No valid data for Build(repo = local, version = local)
As additional information, I'm running npf version 2.0.3 on fedora 41.
As a workaround, j=$(python -c "print($j+1)") does the job, but I think it would be interesting to also support classical bash arithmetic.
$(( expr )) is a special npf syntax that will invoke python using asteval. So if you want to use the bash usual arithmetic you have to escape it with \$((expr))
That python stuff is deprecated in favor of using ninja as it can grow ugly quickly. But for backward compatibility we have to keep it...
Oh, didn't know you could use this type of expression, thank you for the fast answer !