Skip to content

Instantly share code, notes, and snippets.

@junjuew
Last active September 15, 2017 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junjuew/dc800daf94137e53fdca501950014a21 to your computer and use it in GitHub Desktop.
Save junjuew/dc800daf94137e53fdca501950014a21 to your computer and use it in GitHub Desktop.
Template File for Parsing Command Line Arguments in Bash
#! /bin/bash -ex
# Use -gt 1 to consume two arguments per pass in the loop (e.g. each
# argument has a corresponding value to go with it).
# Use -gt 0 to consume one or more arguments per pass in the loop (e.g.
# some arguments don't have a corresponding value to go with it such
# as in the --default example).
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-i|--input_dir)
INPUT_DIR="$2"
shift
;;
-o|--output_dir)
OUTPUT_DIR="$2"
shift
;;
*) # unknown option
;;
esac
shift # past argument or value
done
echo Input Data From "${INPUT_DIR}"
cd ${INPUT_DIR}
for index in {1..5}
do
if [[ -d "$OUTPUT_DIR" ]]; then
mkdir $OUTPUT_DIR
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment