diff --git a/README.org b/README.org index 9b70519..3101420 100644 --- a/README.org +++ b/README.org @@ -184,7 +184,7 @@ *** Count - This example script counts from/to a number: + This example script counts from/to a number and shows the general usage of /sf/-variables: #+begin_src sh #!/usr/bin/env bash @@ -308,3 +308,51 @@ -h, --help Show this help message -v, --verbose Enable verbose output #+end_example + +*** Greet + + This example greets a user and asks for the age. + It shows the usage of input functions: + + #+begin_src sh + #!/usr/bin/env bash + + # ---------------------- + # sf -- script framework + # ---------------------- + + # Declare sf variables + sfdesc="Greet a person." + + # Include sf, this could be replaced with a long oneliner + source "$(dirname $0)/sf" + + # ---------------------- + # Actual script + # ---------------------- + + sfget "Enter your name" # Get input + echo "Hello ${sfin}!" # Use input + + sfask "Do you want to tell me your age" # Ask for YES/no + if [ "$sfin" == true ]; then # Use answer + sfget "Enter your Age" # Get input + sfask "Is ${sftbf}${sfin}${sftrs} really your age" "no" # Use input and ask for yes/NO + if [ "$sfin" == true ]; then # Use answer + echo "Great!" + else + echo "I knew it!" + fi + fi + #+end_src + + The produced usage: + + #+begin_example + Usage: greet [OPTIONS] + + Greet a person. + + OPTIONS + -h, --help Show this help message + #+end_example diff --git a/examples/greet b/examples/greet new file mode 100755 index 0000000..482721b --- /dev/null +++ b/examples/greet @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# ---------------------- +# sf -- script framework +# ---------------------- + +# Declare sf variables +sfdesc="Greet a person." + +# Include sf, this could be replaced with a long oneliner +source "$(dirname $0)/../sf" + +# ---------------------- +# Actual script +# ---------------------- + +sfget "Enter your name" # Get input +echo "Hello ${sfin}!" # Use input + +sfask "Do you want to tell me your age" # Ask for YES/no +if [ "$sfin" == true ]; then # Use answer + sfget "Enter your Age" # Get input + sfask "Is ${sftbf}${sfin}${sftrs} really your age" "no" # Use input and ask for yes/NO + if [ "$sfin" == true ]; then # Use answer + echo "Great!" + else + echo "I knew it!" + fi +fi