Multiple Variables for BASH script

Hello, I am new to the whole "scripting" thing. Below is the script that I have so far and where i need the Variables to go (VAR#)

#!/bin/bash
#Sample Script

VAR1=

echo "Choose an option: 1) Create a file. 2) Delete a file. 3) Move a file." 
read VAR1

case $VAR1 in
  1)
   echo "Pick new file name."
touch VAR2   
;;
  2)
   echo "Pick name of file to delete:"
rm VAR2
   ;;
  3)
   echo "Select Source File:"
read VAR2
   echo "Select Destination:"
read VAR3
   ;;  
  *)
   echo "Invalid option, please try again."
   ;;
esac

Im just not sure where in the script to include what VAR2 and VAR3 = would it be in the same area as VAR1= is located? please help if someone could.

store their choice in a variable named VAR2
store their choice in a variable named VAR3

---------- Post updated at 03:26 AM ---------- Previous update was at 03:06 AM ----------

oh also forgot to mention that I am using ubuntu 9.10

You use 'read myVar' keyword to store the input from stdin (keyboard) into variable myVar. So you just need to read the input for each case. Now when you reference variable, that is when you are retrieving the information stored behind it, you use dollar sign, which you were missing in touch and rm commands.

#!/bin/bash
#Sample Script

VAR1=

echo "Choose an option: 1) Create a file. 2) Delete a file. 3) Move a file." 
read VAR1

case $VAR1 in
  1)
   echo "Pick new file name."
   read VAR2
   touch $VAR2   
;;
  2)
   echo "Pick name of file to delete:"
   read VAR2
   rm $VAR2
   ;;
  3)
   echo "Select Source File:"
read VAR2
   echo "Select Destination:"
read VAR3
echo "Source is $VAR2 and destination $VAR3"
   ;;  
  *)
   echo "Invalid option, please try again."
   ;;
esac
1 Like

thank you very much. i was hitting a :wall: and was starting to get frustrated.

Huh? Not sure what you're getting at here. All the world can usually execute the 'rm' command. Whether it's run from a script or an interactive prompt, the user still needs to have the appropriate privilege.

Regards,
Alister

you're right Alister, I didn't think it through. Comment deleted :-\