Skip to content

Instantly share code, notes, and snippets.

@yunghoy
Last active February 18, 2016 17:45
Show Gist options
  • Save yunghoy/6b0f76e53c18e91280dc to your computer and use it in GitHub Desktop.
Save yunghoy/6b0f76e53c18e91280dc to your computer and use it in GitHub Desktop.
Author: Yungho Yi 이영호
Date: 2. 19. 2016
Description:
To run a shell script with various commands for Jenkins, I implemented a small shell script function to parse parameters
Possible Parameter Inputs:
-a 1 3 2 4 -b 1 3 2 1 -> (-a 1 3 2 4) (-b 1 3 2 1)
132 1 -a 3 -> (-a 3)
-a 3-2 -> (-a 3-2)
-a -2 -> (-a)
#!/bin/bash
endOff=$#
curOff=0
param=($@)
reg="^[\-][\S]*"
func_param()
{
while [ $curOff -lt $endOff ] && ! [[ ${param[curOff]} =~ $reg ]]
do
echo ${param[curOff]}
let curOff++
done
}
# entry point
# do something here before to parse the regular parameters
while [ $curOff -lt $endOff ]
do
case ${param[curOff]} in
-a) OFFSET=$curOff
let curOff++
echo "option a ${curOff}"
func_param
;;
-b) FILE=$curOff
let curOff++
echo "file b ${curOff}"
func_param
;;
*) let curOff++
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment