Simple Menu for User Input

Posted September 2, 2005 by gevery77 in Bourne shell scripting

This script will create an input screen in BASH that allows the user to enter information just as they would in a window. This is to show the use of simple functions as well as the tput command. The command “tput cup” allows the developer to place the cursor anywhere on the screen. There are many more commands that tput recognizes. See the main page for more information.


#!/bin/bash

## Clears the screen and builds the user input screen

function screen() {
clear
cat <

The Conversation

Follow the reactions below and share your own thoughts.

  • Sunny

    when i just copy paste your script and try to run, i encountered with below error, please suggest what is wrong… and thx for your script…
    ===============
    ERROR:
    user-input.sh: line 7: syntax error near unexpected token `newline’
    user-input.sh: line 7: `cat

    • LukeS

      there are sever problems in his, try this, its still not perfect, but it works:
      #!/bin/bash

      ## Clears the screen and builds the user input screen

      function screen() {
      clear
      cat

  • Deepa Ca

    `newline or ;’ is not expected.
    at the end of file

  • Metafaniel

    There’s an error in the syntax near the first EOF. The function should look like this:
    function screen(){
    clear
    cat

  • Metafaniel

    Something went wrong when posting the function, it didn’t displayed all the text I wrote, maybe that happened to LukeS back in 2009, so I’ll explain it!

    1) Write the word “function” (without any quotation marks of course!) followed by it’s name, in this example it’s “screen” followed by parenthesis and an open bracket as in the original example:
    2) Write the word “clear” as in the example.
    3) Here’s the original error! Correct it this way: Write the word “cat” followed by an empty space, then two “less than” signs

  • Metafaniel

    4) Copy and paste all the signs and text in the example to create the input form.
    5) Write down “EOF”
    6) Finish the function with a closing bracket }
    7) Copy and paste the rest of the example and try it 😉

    I hope this help you all!

  • Metafaniel

    This blog have issues when posting less than signs…
    My third step, the most important it’s incomplete because I wrote those 2 signs and the rest of the step was deleted. Here it goes again:

    3) Here’s the original error! Correct it this way: Write the word “cat” followed by an empty space, then two “less than” signs then immediately “EOF” (no space between both less than signs and the EOF)

    This will solve the problem =P