Trying to create a bash script, redirecting to youtube links

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:

#!/bin/bash
echo "What type of video do you want to see?"
select video in video1 video2 close_program
case $video in
video1 ) xdg-open
video2 )
close_program ) exit;; esac
done

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

1 Answer

You can improve it by:

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

#!/bin/bash
while true
do printf 'What video do you want to see? (1, 2) or quit' read video case $video in *1 ) xdg-open *2 ) xdg-open [qQ]*) exit;; # for quit, Quit... *) printf 'Please enter 1, 2 or quit' esac
done

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like