2017-06-16 113 views
0

我想移動並重命名一些jpg圖像。他們在13個不同的文件夾中,命名不同。我試圖寫一個簡短的腳本來爲我完成這項工作。不幸的是,第二個for循環不起作用。行echo $ file回聲我「IMAGES」,而不是圖像名稱。重命名並移動多個圖像

#!/bin/sh 

path="/Users/fflach/Desktop/Training/Kindernahrung" 
k=0 

for i in {1..13} ; 
    do 
     currentPath="$path $i 1,30 m" 
     IMAGES="$currentPath/*.jpg" 
     for file in IMAGES ; 
      do 
       k=k+1 
       moveFile="$currentPath/$file" 
       echo $file 
       destination="/Users/fflach/Desktop/Training/New/$k.jpg" 
       mv $moveFile $destination 
      done 
    done 

我怎樣才能改變第二循環,使其遍歷所有.JPG命名圖片?

+1

'嘗試在$ IMAGES文件;' –

回答

2

作爲$ currentPath和$目標變量包含空格必須在雙引號之間以避免分裂。

遞增K:typeset -i kk=k+1或使用算術((k=k+1))

#!/bin/sh 

path="/Users/fflach/Desktop/Training/Kindernahrung" 
typeset -i k=0 

for i in {1..13} ; 
do 
    currentPath="$path $i 1,30 m" 
    for file in "$currentPath"/*.jpg ; 
    do 
     k=k+1 
     moveFile=$file 
     echo "$file" 
     destination="/Users/fflach/Desktop/Training/New/$k.jpg" 
     mv "$moveFile" "$destination" 
    done 
done