Skip to content

Instantly share code, notes, and snippets.

@mosajjal
Created February 22, 2020 04:25
Show Gist options
  • Save mosajjal/f81e186dfc0ab1452d675c6a68b8e53c to your computer and use it in GitHub Desktop.
Save mosajjal/f81e186dfc0ab1452d675c6a68b8e53c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
LINE=$(printf '%0.s=' $(seq 1 ${COLUMNS:-$(tput cols)}))
BLD="\e[1m" #Bold
BLK="\e[5m" #Blink
YLW="\e[33m" #Yellow Text
GRN="\e[32m" #Green Text
RED="\e[31m" #Red Text
YLWBG="\e[43m" #Yellow Background
GRNBG="\e[42m" #Green Background
REDBG="\e[41m" #Red Background
E="\e[0m" #Erase all attributes
echo -e $RED$LINE$E
echo -e $BLD Some Examples: $E '\n'
echo -e Some texts are better $BLD bold $E '\n'
echo -e $RED$LINE$E '\n'
echo -e Some are better when they are $BLK blinking $E ! '\n'
echo -e $RED$LINE$E '\n'
echo -e "Some are even better in $GRNBG background $E or $GRN foreground $E colors :) \n"
echo -e $RED$LINE$E
echo -e "Here's how you parse arguments\n"
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# Initialize our own variables:
output_file=""
verbose=0
while getopts "h?vf:" opt; do
case "$opt" in
h|\?)
echo -e "args: -v for verbosity, -f to define the file etc"
exit 0
;;
v) verbose=1
;;
f) output_file=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "${1:-}" = "--" ] && shift
echo -e "verbose=$verbose, output_file='$output_file', Leftovers: $@"
echo -e "\n$GRN simple FOR loop $E"
echo -e $RED$LINE$E
for OUTPUT in $(printenv)
do
echo $OUTPUT
done
echo -e "\n$GRN simple WHILE loop $E"
echo -e $RED$LINE$E
x=1
while [ $x -le 5 ]
do
echo -e "Welcome $x times"
x=$(( $x + 1 ))
done
echo -e "\n$GRN simple IF statement $E"
echo -e $RED$LINE$E
if date +%s
then
echo -e "I've successfully printed out the date!"
else
echo -e "I made a mistake in the command"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment