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
  • 3
    Post the code that is giving you problems. Commented Jan 9, 2010 at 12:20

3 Answers 3

11

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"
Sign up to request clarification or add additional context in comments.

Comments

4

You might want to check out Whiptail or Dialog with which one can make graphical interfaces inside the terminal.

Here and here is a good resources on how to use whiptail.

And the answers to this question is a good example of how to use Dialog

enter image description here

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.