From 0a5235344461dd9d3b01004d6b2553c869d25ef9 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sun, 2 Jun 2019 02:44:32 -0600 Subject: [PATCH] update comments and vars --- git-proxy/parseargs.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/git-proxy/parseargs.sh b/git-proxy/parseargs.sh index 60f1d20..9ef9037 100644 --- a/git-proxy/parseargs.sh +++ b/git-proxy/parseargs.sh @@ -1,17 +1,18 @@ set -u set -e -# ParseArgs will parse a string that contains quoted strings the same as bash does -# (same as most other *nix shells do). This is secure in the sense that it doesn't do any -# executing or interpeting. However, it also doesn't do any escaping, so you shouldn't pass -# these strings to shells without escaping them. +# ParseArgs will parse a string that contains quoted strings the same +# as bash does (same as most other *nix shells do). This is secure in +# the sense that it doesn't do any executing or interpreting. However, +# it also doesn't do any escaping, so you shouldn't pass these strings +# to shells without escaping them. parseargs() { notquote="-" str=$1 - declare -a m=() + declare -a args=() s="" - # Strip leading space, then trailing space, then add a terminating space. + # Strip leading space, then trailing space, then end with space. str="${str## }" str="${str%% }" str+=" " @@ -19,7 +20,7 @@ parseargs() { last_quote="${notquote}" is_space="" n=$(( ${#str} - 1 )) - i=-1 + for ((i=0;i<=$n;i+=1)); do c="${str:$i:1}" @@ -50,7 +51,7 @@ parseargs() { continue fi is_space="true" - m+=("$s") + args+=("$s") s="" continue fi @@ -60,11 +61,11 @@ parseargs() { done if [ "$last_quote" != "$notquote" ]; then - >&2 echo "error" + >&2 echo "error: quote not terminated" return 1 fi - for arg in "${m[@]}"; do + for arg in "${args[@]}"; do echo "$arg" done return 0