summaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
authorJohn Southworth <john.southworth@vyatta.com>2012-02-13 18:53:57 -0800
committerJohn Southworth <john.southworth@vyatta.com>2012-02-13 18:53:57 -0800
commitc83583b1f07a28ac99172bbf158d3ba599dc7af5 (patch)
tree091a01384acfcde6299705531ffc280bcfd45b29 /functions
parenta6e1a8be64441bef9876fdfaf8e278cdf2299718 (diff)
downloadvyatta-op-c83583b1f07a28ac99172bbf158d3ba599dc7af5.tar.gz
vyatta-op-c83583b1f07a28ac99172bbf158d3ba599dc7af5.zip
Bugfix 7774: fix quoted string variable expression
Diffstat (limited to 'functions')
-rw-r--r--functions/interpreter/vyatta-op-run43
1 files changed, 41 insertions, 2 deletions
diff --git a/functions/interpreter/vyatta-op-run b/functions/interpreter/vyatta-op-run
index 1d460ee..bc01dd2 100644
--- a/functions/interpreter/vyatta-op-run
+++ b/functions/interpreter/vyatta-op-run
@@ -103,11 +103,50 @@ _vyatta_op_conv_run_cmd ()
{
# Substitue bash positional variables
# for the same value in the expanded array
+ local restore_shopts=$( shopt -p extglob nullglob | tr \\n \; )
+ shopt -s extglob
+ shopt -u nullglob
local run_cmd
- run_cmd="$@"
+ run_cmd=$1
run_cmd="${run_cmd/\"\$\@\"/${args[*]}}"
run_cmd="${run_cmd/\$\*/${args[*]}}"
- run_cmd=$(echo -e "$run_cmd" | sed -e 's/\$\([0-9]\)/\$\{args\[\1\]\}/g')
+ inquote=0;
+ outcmd='';
+ OIFS=$IFS
+ IFS=$'\n'
+ regex="'[^']+'"
+ for line in ${run_cmd[@]}; do
+ outline=''
+ if [[ "$line" =~ $regex ]]; then
+ IFS=$OIFS
+ for word in $line; do
+ if [[ $word =~ "'" ]]; then
+ if [[ $inquote == 0 ]]; then
+ inquote=1
+ else
+ inquote=0
+ outline+="$word "
+ continue
+ fi
+ fi
+ if [[ $inquote == 0 ]] &&
+ [[ "$word" =~ \$[0-9] ]]; then
+ word=$( sed -e 's/\$\([0-9]\)/\$\{args\[\1\]\}/g' <<<"$word" )
+ fi
+ outline+="$word "
+ done
+ IFS=$'\n'
+ line=$outline
+ else
+ if [[ "$line" =~ \$[0-9] ]]; then
+ line=$( sed -e 's/\$\([0-9]\)/\$\{args\[\1\]\}/g' <<<"$line" )
+ fi
+ fi
+ outcmd+="$line\n"
+ done
+ run_cmd=$outcmd
+ IFS=$OIFS
+ eval "$restore_shopts"
echo -ne "$run_cmd"
}