From 12653d3bf11f7331130f92ff938464f492edd9b5 Mon Sep 17 00:00:00 2001 From: simono41 Date: Fri, 14 Dec 2018 01:03:17 +0100 Subject: [PATCH] optimierungen --- cutname.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cutname.sh b/cutname.sh index 97f31f3..02ce171 100755 --- a/cutname.sh +++ b/cutname.sh @@ -5,8 +5,25 @@ set -x while (( "$#" )) do - mv ${1} ${1%%-*} + cd "${1%/*}" # gehe ins Verzeichnis + FILENAME=${1##*/} # Dateiname ist alles ab dem letzten '/' + echo "$FILENAME" + + if ! [ -d ${FILENAME%%-*} ]; then + + mv ${FILENAME} ${FILENAME%%-*} + else + + number=1 + while [ -d ${FILENAME%%-*}${number} ] + do + number=`expr ${number} + 1` + done + mv ${FILENAME} ${FILENAME%%-*}${number} + fi + + cd - shift done