sf/examples/greet

37 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# ----------------------
# sf -- script framework
# ----------------------
# Declare sf variables
sfdesc="Greet a person."
sfargs+=("pretty-useless-flag;p;This is a pretty useless flag which is only used to show correct linebreaks of the usage. Change your terminal size and let this print again to see how the output adapts to your window")
sfargs+=("ask-for-lastname;l;Ask for lastname")
# 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
if [ "$ask_for_lastname" == true ]; then # Use variable with underscores instead of dashes
sfget "Enter your lastname" # Get input
echo "Ah I see, your lastname is ${sfin}" # Use input
fi
sfask "Do you want to tell me your age" # Ask for YES/no
if [ "$sfin" == true ]; then # Use answer
sfget "Enter your Age" "80" # Get input with default value
sfask "Is $sfin 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