0

まったく新しいので.sh、古いiPhoneから画像をバックアップして、日付の新しいディレクトリに画像を保存しようとしています。何百ものディレクトリがあり、それぞれから写真を取得し、それらすべてを 1 つのディレクトリにダンプする必要があります。

私の最善の試み:

#!/bin/bash
function process () {

a=1
for i in *
do
  cp -r i ${dir}
  let a=a+1
done

}

#Interview
echo "This script will take the contents of each directory in the current directory and move it's contents into a new directory that you will specify"
echo "Name your new directory"
read dir

#Confirm
read -p "Your new directory will be ${dir}. Continue?" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
  then
  process
fi

受信したエラー:

massmove.sh: line 1: $'\r': command not found
massmove.sh: line 2: $'\r': command not found
massmove.sh: line 3: $'\r': command not found
massmove.sh: line 4: syntax error near unexpected token `$'{\r''
'assmove.sh: line 4: `function process () {

更新:deefffの回答で改善:

function process () {

for i in */*.*
do
  cp -r $i ${dir}

done

}

echo "This script will take the contents of each directory in the current directory and mv it's contents into a new directory that you will specify"
echo "Name your new directory"
read dir
mkdir ${dir}

echo process

それでもこれらのエラーがスローされます:

massmove.sh: line 2: syntax error near unexpected token `$'{\r''
'assmove.sh: line 2: `function process () {

これは WSL のバグでしょうか?

という事は承知しています

 cp */*.* ${dir}

私の仕事を達成するための迅速かつ強力な方法ですが、エラーの原因にも非常に興味があります。

4

3 に答える 3