Bash 스크립트 공백 준수

Bash 스크립트 공백 준수

정리할 파일이 엄청나게 많습니다. 터무니없는 폴더 구조의 JPG 파일입니다.

모든 파일을 실제 위치에서 정리된 폴더 구조로 이동하고 경로에 정보를 보존해야 하기 때문에 실제 위치를 EXIF ​​주석으로 저장해야 합니다.

예를 들어 다음 경로의 파일이 있습니다.

/OLD ARCHIVE/ORGANIZATION 1/1 환상적인 이벤트/1995 PIPPO가 뭔가를 합니다.jpg

대상은 다음과 같습니다: Archive Digital/AA/1995_BB_000002.jpg

내 생각은 fname var에 모든 정보를 갖기 위해 OLD ARCHIVE/ 경로에서 스크립트를 실행하는 것입니다. 그런 다음 fname var에서 정보를 추출하여 EXIF(및 경로)에 넣고 마지막에 내가 수행 중인 작업을 기록하는 파일을 이동합니다.

나는 이것을 Bash에서 작성하고 있는데, 작동하고 있었지만 공백 관리에 문제가 있어서 공백을 준수하도록 만들려고 노력했지만 더 이상 작동하지 않습니다.

누군가 나를 도와줄 수 있나요?

미리 감사드립니다.

#!/bin/bash
#Parametri: CartellaOriginale CartellaOutput Prefisso NumeroIniziale Keywords
filenamePrefix="$3"
filenameNumber=$(printf "%05d" $4)
data=$(date +%F)
filelog="fileMovedLog_$data.txt"
CommonKeywords="$5"
echo "DEV Working on $1"
echo "DEV output folder $2"
echo "DEV filename start $filenamePrefix$filenameNumber"
echo "$1/$filelog"
echo "Backup in ${1%\/}_BAK/"
#echo "$data"
read -p "Press enter to continue"
echo 'Backup in corso'
#cp -R "$1" "${1%\/}_BAK/"
echo 'Backup terminato, inizio elaborazione'
#mkdir "$2"
touch "$1/$filelog"
find "$1" -name "*.jpg" -or -name "*.JPG" -type f -not -path "*_BAK"| while read fname; do
    echo "$fname"
#Chiedo l'anno
    forseAnno=$(echo `grep -oP  '(?<!\d)\d{4}(?!\d)' <<< "$fname"`)
    if [ -z "$forseAnno" ]
    then 
        forseAnno='ND'
    fi
    echo "Inserire cartella anno dove inserire la foto oppure lasciare vuoto se $forseAnno"
    read annoIn </dev/tty

    if [ -z "$annoIn" ]
    then #Se input è vuoto
        anno="$forseAnno"
    else #ho input, metto lì.
        anno="$annoIn"
    fi
    
    #echo "$anno"   
#Keyword per Lightroom
    #Estraggo alcune possibili KeyWord
    string=${fname,,}
    extraKey=''
    if grep -q 'palio' <<< "$string"; then
        extraKey=',palio del niballo'
    fi
    if grep -q 'dama' <<< "$string"; then
        extraKey="${extraKey},dama"
    fi
    if grep -q 'not' <<< "$string"; then
        extraKey="${extraKey},nott de biso"
    fi
    if grep -q 'cavaliere' <<< "$string"; then
        extraKey="${extraKey},cavaliere"
    fi
    if grep -q 'bigorda' <<< "$string"; then
        extraKey="${extraKey},bigorda"
    fi
    if grep -q 'corteo' <<< "$string"; then
        extraKey="${extraKey},corteo"
    fi
    if grep -q 'paggi' <<< "$string"; then
        extraKey="${extraKey},paggi"
    fi
    echo "$extraKey"
    read -e -p "Correggere le Keywords: " -i "$anno,$CommonKeywords$extraKey" KEYWORD </dev/tty
    suffix=$(printf "%05d" $filenameNumber)
    exiftool -p -Keywords='"$KEYWORD $fname"' -overwrite_original
#Registro il precedente nome file nella descrizione
    exiftool -p -Description+=\''ERA: "$fname"'\' "$fname" -overwrite_original  
    
#Sistemo la CreateDate
    echo `exiftool -wm cg -CreateDate=\'"$anno":01:01 00:00:00\' -overwrite_original "$fname"`
    if [ $? -ne 0 ] #avevo già una data
    then
        datafile=(exiftool -S -createdate "$fname")
        while true 
        do 
            if [ $anno -lt 2021 ] #la scrittura della data in EXIF la faccio solo se è un anno minore di 2021. Se ho messo 5060 per indicare anni 50-60 non lo metto
            then 
                    read -e -p "Sovrascrivere la data $datafile con $anno?[Yes/No/Vuoto]" -i "Y" yn </dev/tty
            else
                    read -e -p "Sovrascrivere la data $datafile con $anno?[Yes/No/Vuoto]" -i "N" yn </dev/tty
            fi
            case $yn in 
                [Yy]* ) exiftool -p -CreateDate=\'"$anno":01:01 00:00:00\' -overwrite_original;break;;
                [Nn]* ) break;; #Non fo una sega
                [0123456789][0123456789][0123456789][0123456789]* ) exiftool -p -CreateDate=\'"$yn":01:01 00:00:00\' -overwrite_original;break;;
                * ) echo "Inserire Y[es]/N[o] o l'anno";;
            esac
        done
    fi
#Procedo allo spostamento e logging
    echo 'Sposto '"$fname $2/$anno/$filenamePrefix$suffix.jpg"
    read -p "Confermi?"
    mv \""$fname"\" \""$2/$anno/$filenamePrefix$suffix.jpg"\"
    echo "\"$fname\"; \"$filenamePrefix$suffix.jpg\"" >>$1/$filelog
    ((filenameNumber++))
    echo ""
done
echo "Completato";

관련 정보