tags:

views:

78

answers:

3

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.

+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
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
+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