From 29fe67b7995d0db5e96df6f949acc06c94a54e82 Mon Sep 17 00:00:00 2001 From: KlzXS Date: Wed, 11 Mar 2020 13:20:55 +0100 Subject: [PATCH] Addressing #489 (#490) * Fix empty printf, change separator for sed * Added missing quotes --- plugins/batchrename | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/plugins/batchrename b/plugins/batchrename index 23dc9a3f..b22b9ae2 100755 --- a/plugins/batchrename +++ b/plugins/batchrename @@ -42,14 +42,16 @@ while read -r num name; do fi printf "%s: unable to parse line, aborting\n" "$0" + exit 1 fi # check if $num is an integer if [ ! "$num" -eq "$num" ] 2> /dev/null; then printf "%s: unable to parse line, aborting\n" "$0" + exit 1 fi - src=$(eval printf "%s" "\${$num}") + src=$(eval printf "%s" "\"\${$num}\"") if [ -z "$src" ]; then printf "%s: unknown item number %s\n" "$0" "$num" > /dev/stderr @@ -65,14 +67,14 @@ while read -r num name; do c=1 new_args="" while [ $c -le $# ]; do - tmp=$(eval printf "%s" "\${$c}") + tmp=$(eval printf "%s" "\"\${$c}\"") if [ "$c" -eq "$num" ]; then new_args="$new_args ''" else if [ -z "$tmp" ]; then tmp="''" else - tmp=$(printf %s "$tmp" | sed "s/'/'\\\\''/g;s/^\(.*\)$/'\1'/") + tmp=$(printf "%s" "$tmp" | sed "s/'/'\\\\''/g;s/^\(.*\)$/'\1'/") fi new_args="$new_args $tmp" fi @@ -103,15 +105,15 @@ while read -r num name; do c=1 new_args="" while [ $c -le $# ]; do - item=$(eval printf "%s" "\${$c}") + item=$(eval printf "%s" "\"\${$c}\"") if [ "$item" = "$name" ]; then - item=$(printf %s "$tmp" | sed "s/'/'\\\\''/g;s/^\(.*\)$/'\1'/") + item=$(printf "%s" "$tmp" | sed "s/'/'\\\\''/g;s/^\(.*\)$/'\1'/") new_args="$new_args $item" else if [ -z "$item" ]; then item="''" else - item=$(printf %s "$item" | sed "s/'/'\\\\''/g;s/^\(.*\)$/'\1'/") + item=$(printf "%s" "$item" | sed "s/'/'\\\\''/g;s/^\(.*\)$/'\1'/") fi new_args="$new_args $item" fi @@ -134,11 +136,11 @@ while read -r num name; do c=1 new_args="" while [ $c -le $# ]; do - tmp=$(eval printf "\${$c}") + tmp=$(eval printf "\"\${$c}\"") if [ -z "$tmp" ]; then tmp="''" else - tmp=$(printf "%s" "$tmp" | sed "s/^$src\(\$\|\/\)/$name\1/;s/'/'\\\\''/g;s/^\(.*\)$/'\1'/") + tmp=$(printf "%s" "$tmp" | sed "s|^$src\(\$\|\/\)|$name\1|;s/'/'\\\\''/g;s/^\(.*\)$/'\1'/") fi new_args="$new_args $tmp" c=$((c+1)) @@ -153,14 +155,14 @@ while read -r num name; do c=1 new_args="" while [ $c -le $# ]; do - tmp=$(eval printf "%s" "\${$c}") + tmp=$(eval printf "%s" "\"\${$c}\"") if [ "$c" -eq "$num" ]; then new_args="$new_args ''" else if [ -z "$tmp" ]; then tmp="''" else - tmp=$(printf %s "$tmp" | sed "s/'/'\\\\''/g;s/^\(.*\)$/'\1'/") + tmp=$(printf "%s" "$tmp" | sed "s/'/'\\\\''/g;s/^\(.*\)$/'\1'/") fi new_args="$new_args $tmp" fi @@ -173,7 +175,7 @@ done <"$dst_file" c=1 new_args="" while [ $c -le $# ]; do - tmp=$(eval printf "%s" "\${$c}") + tmp=$(eval printf "%s" "\"\${$c}\"") if [ -n "$tmp" ]; then rm -ri "$tmp" fi