I want to write Bash Script with User Input for my assignment called "book store service". Firstly, it has option menu like "add new book name " "author name" "remove book" "update" "search" "show book list" "Exit". If I choice option 1, I've got to input new book's name. How could I write the user input and display output data when I choice "show book list" option. I've got trouble with this Assignment. Pls someone help me to clear about this, that would be really helpful and thankful to all of you.
views:
78answers:
3
+1
A:
Here is a code example that shows how to read user input: http://tldp.org/LDP/abs/html/internal.html#READR
You can also use CLI arguments:
test.sh
echo $1
CLI:
$ ./test.sh testinput
testinput
Frank
2010-01-09 12:25:18
A:
you should check out this page on how to use case/esac or select to create menus
Also, don't forget to start reading the whole document to learn about shell scripting
ghostdog74
2010-01-09 12:27:22
+2
A:
Take a look at the select
statement. It allows you to create a menu.
PS3="Please choose an option "
select option in go stay wait quit
do
case $option in
go)
echo "Going";;
stay|wait)
echo "Standing by";;
quit)
break;;
esac
done
Which would look like:
1) go
2) stay
3) wait
4) quit
Please choose an option
Edit:
One of your options might prompt for user input:
read -rp "Enter a phrase: " phrase
echo "The phrase you entered was $phrase"
Dennis Williamson
2010-01-09 12:40:25