bash:嵌套的选择菜单,仅第一个选择起作用,第二个选择不起作用 [英] bash: nested select menu, only first selection works, the second selection doesnt
问题描述
我的脚本中有两个功能,两个都是嵌套在其中的选择"菜单.它们都起作用,但是仅第一个选择有效,而第二个选择无效.我显然对他们俩都做错了.现在,我将仅提供我的一个功能,因为我猜我在两个功能上都犯了相同的错误.
I have two functions in my script, both are 'select' menus with other 'select' menus nested within. Both of them work, but only the first selection, not the second selection. I am obviously doing something wrong on them both. For now, I will provide just one of my functions as Im guessing that I am making the same mistake on both of them.
问题:第一个菜单的所有第一部分(流")都可以正常运行,而第二部分(下载")则不能.
Problem: All of the first part of the first menu ("Stream") works perfectly, the second part ("Download") does not though.
为什么不起作用?我在做什么错?
#!/bin/env bash
MAIN(){
echo "Stream Or Download?"
select S_D in 'Stream' 'Download'; do
case $S_D in
Stream)
echo "Audio Or Video?"
select A_V in 'Audio' 'Video'; do
case $A_V in
Audio)
if [[ "$DOMAIN" =~ 'youtube' ]]; then
mpv --no-video "$URL"
else
streamlink --player='mpv --no-video' "$URL" 720p|& tee /dev/null
fi
break 2 ;;
Video)
if [[ "$DOMAIN" =~ 'youtube' ]]; then
am start -a android.intent.action.VIEW -d "$(youtube-dl -f best -g "$URL")" -n is.xyz.mpv/.MPVActivity &> /dev/null
else
am start -a android.intent.action.VIEW -d "$(streamlink "$URL")" -n is.xyz.mpv/.MPVActivity &> /dev/null
fi
break 2 ;;
Download)
echo "Song? Album? Playlist?"
select S_A_P in 'Song' 'Album' 'Playlist'; do
case $S_A_P in
Song)
echo "Enter Artist:"
read ARTIST
echo "Enter Song:"
read SONG
youtube-dl --extract-audio --prefer-ffmpeg --audio-format m4a --output "$MUSIC_DIR/$ARTIST - $SONG.%(ext)s" "$URL"
mid3v2 -v -a "$ARTIST" -S "$SONG" "$MUSIC_DIR/$ARTIST - $SONG.m4a"
break 2 ;;
Album)
echo "Enter Artist:"
read ARTIST
echo "Enter Album:"
read ALBUM
youtube-dl --extract-audio --prefer-ffmpeg --audio-format m4a --output "$MUSIC_DIR/$ARTIST - $ALBUM.%(ext)s" "$URL"
mid3v2 -v -a "$ARTIST" -A "$ALBUM" "$MUSIC_DIR/$ARTIST - $ALBUM.m4a"
break 2 ;;
Playlist)
echo "Enter Artist/DJ Or Leave It Empty:"
read ARTIST
echo "Enter A Title:"
read TITLE
if [[ -z "$ARTIST" ]]; then
youtube-dl --extract-audio --prefer-ffmpeg --audio-format m4a --output "$MUSIC_DIR/$TITLE.%(ext)s" "$URL"
mid3v2 -v -A "$TITLE" "$MUSIC_DIR/$TITLE.m4a"
else
youtube-dl --extract-audio --prefer-ffmpeg --audio-format m4a --output "$MUSIC_DIR/$ARTIST - $TITLE.%(ext)s" "$URL"
mid3v2 -v -a "$ARTIST" -A "$TITLE" "$MUSIC_DIR/$ARTIST - $TITLE.m4a"
fi
break ;;
esac
done
break ;;
esac
done
break ;;
esac
done
}
推荐答案
假定 case $ A_V
块只有2个选项( Audio
, Video
),则匹配的 esac
语句放置在错误的位置(混乱的缩进无济于事):
Assuming the case $A_V
block has just 2 options (Audio
, Video
), the matching esac
statement is in the wrong place (messy indentations don't help):
case $S_D in
Stream)
...
case $A_V in
Audio)
...
Video)
...
# `esac` for `case $A_V` should reside on this line
Download)
...
case $S_A_P in
Song)
...
Album)
...
Playlist)
...
esac # first esac closes `case $S_A_P`
...
esac # second esac closes `case $A_V` **THIS IS THE PROBLEM! THIS NEEDS TO BE MOVED JUST BEFORE THE ** `Download` **LINE.**
...
esac # last esac closes `case $S_D`
注意::OP还需要使用 esac
语句
NOTE: OP will also need to move the associated done/break
statements with the esac
statement
原因:每个单独的 select
菜单都必须以 esac
/ done
结尾不继续下一个选择.OP没有正确关闭 case $ A_V
.
REASON: Each individual select
menu must finish with esac
/done
at the very end or it will not continue to the next selection. OP didnt close case $A_V
properly.
这篇关于bash:嵌套的选择菜单,仅第一个选择起作用,第二个选择不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!