This is a simple loop menu script that I have for class. The goal was to make a menu with applicable commands.
- A. Greet me. (Greet the user by their username (using the whoami command with back ticks))
- B. Create a file in my home directory. (Ask the user what they want to name the file. Make sure the file does not already exist, using an if statement)
- C. Search for a file. (Ask the user for the starting location of the file and the name. Use the find command)
- D. Exit
I have 0 confidence in my scripting skills as I'm learning, so could you help me out? I don't know if put
;; at the end of choices like
read filescript;;, so on. Also, I'm not very sure of my choice C, creating in home directory.
#!/bin/bash # # This is Script 2 written by Jake Smoak # # CHOICE=7 until [ $CHOICE -eq 4 ] do clear echo Please select a menu item echo echo "A.) "Greet Me" echo "B.) "Create a file in my home directory" echo "C.) "Search for a file" echo "D.) "Exit" echo read CHOICE case $CHOICE in A) echo "Hello $(whoami)." B) echo "What would like to name the file?" touch FILENAME;; if [ -a $FILENAME ] then echo "Sorry, this file is already made" C) echo -n "Enter the location where the search should start. " read STARTLOCATION echo -n "What is the name of the file to search for? " read FILENAME echo "Search starting for the $FILENAME file in the $STARTLOCATION directory" find $STARTLOCATION -name $FILENAME 2> /dev/null D) echo "Sorry to see you go :(" *) echo You have made a mistake, Please try again" esac echo "Press Enter to continue" read Enter done