Continue an SFK script at a different point, or stop the script due to a condition with sfk if.
sfk ... +if [opts] expression command1 ... +command2sfk ... +[t]if expr [+]begin +cmd1a +cmd1b ... +endif +cmd2
execute command1 if expression is true, then continue to command2.
if expression is not true, skip directly to command2.
can be used only in a command chain, after another command.
use "+if expr +begin ... +endif" to run multiple commands
as one block, if expression is true.
supported expressionsreturn code comparison
"rc=n" return code of previous command equal to n
"rc>n" return code of previous command higher than n
"rc<n" return code of previous command lower than n
"rc<>n" return code of previous comm. not equal to n
generic text or number comparison
"l = r" left part is equal to right
"l <> r" left part is not equal to right
"l < r" left part is lower then right
"l > r" left part is higher then right
"l <= r" left part is lower or equal
"l >= r" left part is higher or equal
if both l and r contain only digits a numeric
comparison is done, else a text comparison.
options
options for if must be given before expression.
-var use sfk variables, must be first option
-text force text comparison (nocase)
-case case sensitive text comparison
-debug tell what is done in a generic comparison
limited nestingif ... begin ... endif
- may not contain other if[exist] / begin / endif
- but may contain short if ... without begin.
invalid nesting causes an undefined program flow.
chaining support since sfk 1.9.3+if does not accept any chain input data, as this
creates ambiguities with many following
commands, like +if ... +setvar a=text
+tif expects text and stream chain input data.
bad example:+xed /a/b/ +if ... +xed /b/c/
data cannot be passed from the first to the
second xed this way, as +if will block this.
correction:+xed /a/b/ +tif ... +xed /b/c/
the +tif explicitely requests text data.
you may also use global option -keepdata.
for more details see: sfk help chainsee alsosfk ifexist check if a file or folder exists.
sfk call call sub functions in a script.
sfk goto jump to a local label.
examplessfk filter in.txt -+err +if "rc>0" run -yes "x.bat" +echo done
if file in.txt contains the word "err", run x.bat.
the "echo done" is always executed.
sfk xex -justrc in.txt "/foo*bar/"+if "rc=0" stop 9 "[Red]error:[def] miss" +echo "match"
type this all in one line, or use "sfk cmd 18". [18]
if file in.txt does not contain the search pattern
then stop with return code 9, printing an error.