Simple Bash framework which provides argument parsing, usage output and text formatting variables
Find a file
2022-01-07 07:09:36 +01:00
README.org update README 2022-01-07 07:09:36 +01:00
sf small fixes 2022-01-07 07:09:29 +01:00

\* sf

script framework

Example

  sfname="calc"
  sfdesc="A simple calculator which can add and subtract."

  sfargs+=("A;First number")
  sfargs+=("B;Second number")
  sfargs+=("substract;s;Substract B from A")
  sfargs+=("multiply;m;MULTIPLICATOR;1;Multiply the result with MULTIPLICATOR")

  sfexamples+=("calc 3 5;Prints the result of 3 + 5")
  sfexamples+=("calc -s 2 1;Prints the result of 2 - 1")
  sfexamples+=("calc -m 3 -s 2 1;Prints the result of (2 - 1) * 3")

  sfextrausage="No copyright at all."

  source sf

  res=0
  if [ "$substract" == true ]; then
      res=`expr $A - $B`
  else
      res=`expr $A + $B`
  fi

  if [ "$multiply" -ge 1 ]; then
      res=`expr $res \* $multiply`
  fi

  echo "The result is $sftbf$res$sftrst."

Help output:

  Usage: calc OPTIONS A B

  A simple calculator which can add and subtract.

  POSITIONAL ARGUMENTS
    A  First number
    B  Second number

  OPTIONS
    -s, --substract               Substract B from A
    -m, --multiply MULTIPLICATOR  Multiply the result with MULTIPLICATOR (default:
                                   1)

  EXAMPLES
    calc 3 5          Prints the result of 3 + 5
    calc -s 2 1       Prints the result of 2 - 1
    calc -m 3 -s 2 1  Prints the result of (2 - 1) * 3

  No copyright at all.

Script output:

  The result is 8.