I want to create this bash function as an alias in .zshrc to play Twitch channels with MPV from the terminal, but it gives me errors related to if statements and square brackets. The function requires the user to enter one ($1, channel number in the array) or two arguments ($2, d to see the channel live).
t () {
# List of channel's usernames.
channels=("list" "ibbaa" "shabs" "alisa" "corky" "crutch_" "rollipollipotamus" "marcelek" "fuzzface49" "zuluxxman" "hollywoodboblive" "simplymatthias")
# Default values for live channels.
live="/"
speed="1.0"
# If the user enters 0 show a list of available channels.
if [ "$1" = "0" ]; then
for i in ${!channels[@]}; do
echo "Enter $i for ${channels[$i]} channel."
else
# "d" must be entered as second argument for play live channels. Otherwise play the latest channel's videos at 2x changing the default values.
if [ "$2" != "d" ]; then
live="/videos"
speed="2.0"
fi
mpv --speed="$speed" --video-aspect-override=16:10 --fullscreen=yes https://www.twitch.tv/"${channels[$1]}""$live"
fi
}
Currently it indicates these errors:
/home/alex/.zshrc:119: parse error near `}'
/home/alex/.zshrc:119: parse error near `else'
/home/alex/.zshrc:120: parse error near `fi'
New contributor
Alex is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.