I'm trying to create a bash script.I never wrote bash in my life, I haven't even used Linux ever, so, after a bit of googling and thinking I decided to create a script that asks you the question "Which video do you wanna watch?" and it giving you 3 options, 2 for 2 videos and 1 to close the script.After a bit of googling and studying, this is the code I came up with:


echo "What type of video do you want to see?"

select video in video1 video2 close_program
case $video in
video1 ) xdg-open https://www.youtube.com/watch?v=xQ9MpPIs1jM

video2 ) https://www.youtube.com/watch?v=T2uWvrwq4T4

close_program ) exit;;


Of course, it's not perfect, so here I am, asking for tips to improve it.


You can improve it by:

  • putting it in a while loop (if user enter other choice)
  • have shorter options:

while true
        printf 'What video do you want to see? (1, 2) or quit'
        read video

        case $video in
            *1 ) xdg-open https://www.youtube.com/watch?v=xQ9MpPIs1jM;;
            *2 ) xdg-open https://www.youtube.com/watch?v=T2uWvrwq4T4;;
            [qQ]*) exit;; # for quit, Quit...
            *) printf 'Please enter 1, 2 or quit'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.