Skip to content

Instantly share code, notes, and snippets.

@qinshulei
Created October 22, 2014 07:03
Show Gist options
  • Save qinshulei/5ff2f4f78f46c9eb3914 to your computer and use it in GitHub Desktop.
Save qinshulei/5ff2f4f78f46c9eb3914 to your computer and use it in GitHub Desktop.
bash-space-separated
#!/bin/bash
#usage: ./myscript.sh -e conf -s /etc -l /usr/lib /etc/hosts
while [[ $# > 1 ]]
do
key="$1"
shift
case $key in
-e|--extension)
EXTENSION="$1"
shift
;;
-s|--searchpath)
SEARCHPATH="$1"
shift
;;
-l|--lib)
LIBPATH="$1"
shift
;;
--default)
DEFAULT=YES
shift
;;
*)
# unknown option
;;
esac
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