全新的.sh
,我正在尝试从旧 iPhone 备份图像,其中图像被放置到新目录中以供日期。有数百个目录,我需要从每个目录中获取图片并将它们全部转储到一个目录中。
我最好的尝试:
#!/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}
是完成我的任务的一种快速而强大的方法,但我也对导致错误的原因非常感兴趣。