Last active
November 25, 2020 08:00
Revisions
-
kolodny revised this gist
Nov 18, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ function parse_args() { local value="${arg#*=}" eval $key=\$value ;; --?*) local key=${arg#--} if [ ! ${!key+x} ]; then echo "invalid option -- $key" 1>&2 -
kolodny revised this gist
Nov 18, 2016 . 1 changed file with 37 additions and 11 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,51 @@ #!/bin/sh set -euo pipefail #declare valid arguments here bar= baz= function parse_args() { args=() local i=1 while [ $i -le $# ]; do local arg="${!i}" case "${arg}" in --*=*) arg=${arg#--} local key="${arg%=*}" if [ ! ${!key+x} ]; then echo "invalid option -- $key" 1>&2 exit 2 fi local value="${arg#*=}" eval $key=\$value ;; --*) local key=${arg#--} if [ ! ${!key+x} ]; then echo "invalid option -- $key" 1>&2 exit 2 fi if [ $i -ge $# ]; then echo "option requires an argument -- $key" 1>&2 exit 2 fi let "i++" local value=${!i} eval $key=\$value ;; *) args+=("$arg") esac let "i++" done } parse_args "$@" echo "bar is $bar" echo "baz is $baz" for arg in "${args[@]}"; do echo "arg is $arg" done -
kolodny revised this gist
Nov 17, 2016 . 1 changed file with 23 additions and 24 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,26 +1,25 @@ #!/bin/bash function parse_args() { args=() for (( i=1; i<=$#; i++ )); do local arg="${!i}" case "${arg}" in --*=*) arg="${!i}" arg=${arg#--} readonly "${arg%=*}"="${arg#*=}" continue ;; --*) ((i++)) arg=${arg#--} readonly "${arg}"="${!i}" continue ;; *) args+=("$arg") esac done } parse_args "$@" -
kolodny revised this gist
Nov 17, 2016 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,6 @@ args=() for (( i=1; i<=$#; i++ )); do arg="${!i}" case "${arg}" in --*=*) arg="${!i}" -
kolodny created this gist
Nov 17, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ #!/bin/bash args=() for (( i=1; i<=$#; i++ )); do arg="${!i}" # echo "about to examine $arg" case "${arg}" in --*=*) arg="${!i}" arg=${arg#--} declare "${arg%=*}"="${arg#*=}" continue ;; --*) ((i++)) declare "${arg}"="${!i}" continue ;; *) args+=("$arg") esac done for arg in "${args[@]}"; do echo "arg is $arg" done