我尝试创建一个将运行文件列表的脚本,并为每个文件创建一个增量目录,然后将该文件移动到新目录中。我一直坚持让文件移动。
n=1
for file in /Users/scrawfo/Desktop/untitled\ folder/*.zip; do
mkdir /Users/scrawfo/Desktop/untitled\ folder/test/$((n++))
sleep 5s
mv $file /Users/scrawfo/Desktop/untitled\ folder/test/"$((n++))"
done
答案 0 :(得分:2)
看起来您需要两次递增$n
,因此当您移动文件时,该目录不存在。我想你想要:
n=1
for file in /Users/scrawfo/Desktop/untitled\ folder/*.zip; do
mkdir /Users/scrawfo/Desktop/untitled\ folder/test/$n
sleep 5s
mv $file /Users/scrawfo/Desktop/untitled\ folder/test/$n
# Edited per Etan's comment, much less confusing this way
$((n++))
done