簡體   English   中英

如何修復我的 bash 腳本錯誤:意外標記“完成”附近的語法錯誤?

[英]How to fix my bash script from error: syntax error near unexpected token `done'?

我試圖在 Centos7 機器上運行這個 bash 程序。 我嘗試了很多不同的方法,但總是出現此錯誤:

 line 31: syntax error near unexpected token `done' line 31: `done'

第 31 行屬於第一個done

我做了cat -v mybash.bash來檢查奇怪的標記,但沒有。

我的腳本如下:

for mainFolder in *
do
    if [ -d "${mainFolder}" ]
    then
        cd "${mainFolder}" || exit
        echo "Entering in directory ${mainFolder}" 
        cp ../mypy.py .
        chmod +x mypy.py
        ./mypy.py
        echo "Executing mypy.py"
        sleep 1

        for subFolder in *
        do
            if [ -d "${subFolder}" ]
            then
                cd "${subFolder}" || exit
                echo "Entering in directory $subFolder in $mainFolder"
                echo "Submitting slurm file in current directory"
                sbatch *.slurm
                sleep 1
            fi
            cd ..
        done
    fi
    cd ..
done

請幫助我注意我做錯了什么。

我的猜測是 slurm 提交腳本不存在。 以下檢查是否找到一個且不超過一個腳本。

我還移動了cd..僅在cd之后發生。

for mainFolder in *
do
    if [ -d "${mainFolder}" ]
    then
        echo "Entering in directory ${mainFolder}" 
        cd "${mainFolder}" || exit
        cp ../mypy.py .
        chmod +x mypy.py
        echo "Executing mypy.py"
        ./mypy.py
        sleep 1

        for subFolder in *
        do
            if [ -d "${subFolder}" ]
            then
                cd "${subFolder}" || exit
                echo "Entering in directory $subFolder in $mainFolder"
                scripts=$(ls *.slurm)
                nScripts=$(echo $scripts | wc -w)
                if [ $nScripts == 1 ]
                then
                    echo "Submitting $scripts"
                    sbatch $scripts
                elif [ $nScripts == 0 ]
                then
                    echo "Error: No script found"
                else
                    echo "Error: $nScripts scripts found (${scripts})"
                fi
                sleep 1
                cd ..
            fi
        done
        cd ..
    fi
done

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM