Skip to content

Instantly share code, notes, and snippets.

@ephrin
Created May 25, 2015 06:20
Show Gist options
  • Save ephrin/13fb1d62513e0f763312 to your computer and use it in GitHub Desktop.
Save ephrin/13fb1d62513e0f763312 to your computer and use it in GitHub Desktop.
Straight Bash Space Separated Usage `./myscript.sh -e conf -s /etc -l /usr/lib /etc/hosts ` http://linuxgeeks.ru/bash-2.htm
#!/bin/bash
while [[ $# > 1 ]]
do
key="$1"
case $key in
-e|--extension)
EXTENSION="$2"
shift
;;
-s|--searchpath)
SEARCHPATH="$2"
shift
;;
-l|--lib)
LIBPATH="$2"
shift
;;
--default)
DEFAULT=YES
shift
;;
*)
# unknown option
;;
esac
shift
done
echo FILE EXTENSION = "${EXTENSION}"
echo SEARCH PATH = "${SEARCHPATH}"
echo LIBRARY PATH = "${LIBPATH}"
echo "Number files in SEARCH PATH with EXTENSION:" $(ls -1 "${SEARCHPATH}"/*."${EXTENSION}" | wc -l)
if [[ -n $1 ]]; then
echo "Last line of file specified as non-opt/last argument:"
tail -1 $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment