为什么这个脚本会循环?

时间:2016-07-04 10:22:53

标签: bash shell loops while-loop

我写了一个shell脚本来听音乐(在使用el capitan的mac上),但遇到了一些问题 代码是:

#!/bin/sh
KEYF="true";
while [ "$KEYF" == "true" ] ;
    KEYS="true";
    do echo "Pick a song:\n" ; 
    select SONG in Music_Path/* ;
        do echo "You chose to listen to ${SONG}" ;
        break;
        done;
    while [ "$KEYS" == "true" ];
        do mpv "${SONG}" ; 
        echo "Do you want to repeat this song; if so, enter true; if not, enter false.";
        select KEYS in "true" "false"; 
            do echo "You picked $KEYS"; 
            break; 
            done ; 
    done ;
    echo "Do you want to pick a new song; if so, enter true; if not, enter false.";
    select KEYF in "true" "false";
        do echo "You picked $KEYF";
        break;
        done;
done

一切正常,但是在我为KEYFKEYS选择了false之后,该过程循环回来并要求我再次选择一首歌。是不是第一个while循环来阻止这种行为?
真诚的感谢您的帮助。

修改
根据@ 123的评论,问题是KEYS="true";介于第一个和do之间。

0 个答案:

没有答案