Created
October 14, 2017 15:47
-
-
Save Deviad/e8e83c9d439ebd58c566dc2b98f1597e to your computer and use it in GitHub Desktop.
You can use this example-script to wrap a more complicated command, useful when you have tons of options you don't remember
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
sfolder="~/" | |
dfolder="/Applications/" | |
usage() { echo "Usage: $0 [-s <source folder>] [-d <destination folder>]" 1>&2; exit 1; } | |
while getopts ":s:d:" o; do | |
case "${o}" in | |
s) | |
s=${OPTARG} | |
;; | |
d) | |
d=${OPTARG} | |
;; | |
*) | |
usage | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
if [ -s "${s}" ] || [ -d "${d}" ]; then | |
usage | |
fi | |
if ! [[ ${s+x} ]]; then | |
echo "Default source folder used ${sfolder}" 1>&2; | |
else | |
sfolder="${s}" | |
echo "The source folder is ${sfolder}" | |
fi | |
if ! [[ ${d+x} ]]; then | |
echo "Default destination folder used ${dfolder}" 1>&2; | |
else | |
dfolder=${d} | |
echo "The dfolder is ${dfolder}" | |
fi | |
echo "s = ${s}" | |
echo "p = ${d}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment