Simple Bash framework which provides argument parsing, usage output and text formatting variables
Find a file
2022-01-06 15:41:33 +01:00
README.org update README 2022-01-06 15:41:33 +01:00
sf initial commit 2022-01-06 15:37:54 +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:

  $ calc -h
  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 -m 3 -s 2 1  Prints the result of (2 - 1) * 3

  No copyright at all.

Script output:

  The result is 8.