Unexpected result from WolframScript command line

num = ToExpression[$ScriptCommandLine[[2]]];
num2 = ToExpression[$ScriptCommandLine[[3]]];
rs0=x^2;
D[rs0,x];
ff[x_]=%
aa=ff[num+num2]
Print[aa]

Command line:
wolframscript -file second.wls 2 3
The result is Out[0], I don’t know why.
Thank you!

The output from D[rs0,x]; is suppressed, so % defaults to Out[0]. Best to avoid %.

num = ToExpression[$ScriptCommandLine[[2]]];
num2 = ToExpression[$ScriptCommandLine[[3]]];
rs0=x^2;
d=D[rs0,x];
ff[x_]:=Evaluate@d
aa=ff[num+num2];
Print[aa]

Why is it suppressed when using command line, thank you very much!

Not command line specific. The ; and the end of the expression suppresses output even in a notebook.

Ok, thank you!