F 中的脚本 *

Script For F in *

我在 Server 2012 r2 上使用 Cygwin

我正在制作一个脚本,用于根据文件名的一部分(即日期)对文件进行排序。将它们分类到文件夹中

这是脚本。

#!/bin/bash

for f in * ; do
 if [[ $f == *_D????00_* ]] ;
  then
   if ! [[ -e ../2000/$f ]]
    echo "../2000/$f EXISTS"
 else
    echo "Copying $f --> ../2000/$f"
fi
done

我收到这个错误:

$ ./sort.sh
./sort.sh: line 8: syntax error near unexpected token `else'
./sort.sh: line 8: ` else'

对 linux bash 相当陌生,尤其是 cygwin。

想法?

-迈克

你的 then 语句一次正确(以 fi 结束)..但是你忘记为嵌套的 if IE

做这件事
#!/bin/bash
for f in * ; do
    if [[ $f == *_D????00_* ]]
    then
       if ! [[ -e ../2000/$f ]]
       then
            echo "../2000/$f EXISTS"
       else
            echo "Copying $f --> ../2000/$f"
       fi
    fi
done