shell-scripte-code/cutname.sh

31 lines
499 B
Bash
Raw Permalink Normal View History

2019-01-07 20:23:02 +01:00
#!/usr/bin/env bash
2018-12-14 00:43:11 +01:00
set -x
while (( "$#" ))
do
2018-12-14 01:03:17 +01:00
cd "${1%/*}" # gehe ins Verzeichnis
2018-12-14 00:43:11 +01:00
2018-12-14 01:03:17 +01:00
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 -
2018-12-14 00:43:11 +01:00
shift
done
#./cutname.sh <Ordner>/*-*