Last active
September 15, 2017 15:55
-
-
Save junjuew/dc800daf94137e53fdca501950014a21 to your computer and use it in GitHub Desktop.
Template File for Parsing Command Line Arguments in Bash
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
#! /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