shell 脚本报错“syntax error near unexpected token `;'”

运行shell脚本时,报错:“syntax error near unexpected token `;'”

shell脚本如下:

#!/bin/bash

filesizes=($(du -sm * | grep *.txt | awk '{print$1}'))

for ((i=0;i<${#filesizes[*]};i++));do
    echo -e "filesizes:${filesizes[$i]}\n}"
    let filesize=($(filesizes[i])
    if [ $filesize -gt 2 ]
        then
        filename=${filesize[$i-1]}
        for ((j=0;j<5;j++ ));do
            sleep 10
            echo "****************"${i}
            tryvalue=($(du -sm * | grep ${filename} |awk '{print$1}'))
            let tryvalue=($(filesize[j]))
            if [$tryvalue -gt $filesize];then
                mv -rf $filenam
                break
            else
                continue
                echo "continue"
       






            fi
            done



    fi
---------------------------------------------------------------------------------------------------------------------------------

[root@vm-156-223-dev03-hp letv]# sh filechangesize.sh
filechangesize.sh: line 8: syntax error near unexpected token `;'
filechangesize.sh: line 8: `    if [ $filesize -gt 2 ];then'

网上有说是:if 与‘['之间没有加空格导致的导致,但我的是加过空格的,还是不行,之后换成then换行的格式就在报这个错了,换行then 写法,if 后面不用加“;”

----------------------------------------------------------------------------------------------------------------------------------

你可能感兴趣的:(linux)