mvw/setup.sh

64 lines
1.2 KiB
Bash
Raw Normal View History

2024-12-31 11:55:33 +01:00
#!/bin/sh
set -u # Throw errors when unset variables are used
set -e # Exit on error
#set -o pipefail # Bash specific
usage() {
echo "Tool to BLAH BLAH BLAH"
echo
echo "Usage:"
echo "$0 [-eh] [-a <arg>] <blabla>"
echo
echo "-a <arg> Option with argument"
echo "-e Example option"
echo "-h This help message"
exit
}
askyn() {
while true; do
printf '%s ' "$1 "
read -r yn
case $yn in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
* ) echo "Please answer [y]es or [n]o.";;
esac
done
}
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# Initialize our own variables:
ARGUMENT=""
EXAMPLE=""
# getopts only allows single letter options (but is apparently the most
# portable). If you want multi letter options (eg --help) use getopt.
while getopts "hea:" opt; do
case "$opt" in
a) ARGUMENT="$OPTARG";;
h)
usage
;;
e) EXAMPLE="-e" ;;
?) exit 1 ;; # message provided by getopts
esac
done
shift $((OPTIND-1))
[ $# -ge 1 ] && [ "$1" = "--" ] && shift
MYDIR=$(dirname "$(realpath "$0")")
TESTDIR="${MYDIR}/test"
mkdir -p "${TESTDIR}"
rm "${TESTDIR}/*"
touch "${TESTDIR}/aaa"
touch "${TESTDIR}/bbb"
touch "${TESTDIR}/ccc"
touch "${TESTDIR}/ëëë"