How Prompt for Input in Bash

Bash is a shell for Linux and Unix operating systems. But bash also provides some basic programming environment acting like a Programming language. System administrators generally develops simple scripts and apps with bash and reads some input from shell interactively. In this tutorial we will look ho to read input from interactive bash console or terminal.

By Using Read

One way to get input from shell prompt is read. We use read and and question text to show and end of the line the variable name. This is the simplest form of getting an yes , no prompt from user.

The other way with read is following printing text before and reading input after text with read.

By Using Select

Another way to read input from bash shell is using conditional statement select . This will read from console and set provided value to the ans bash variable.

By Using Whiptail

There is a library developed with ncurses which provides simple GUI for bash. Whiptail is used to read user input with a more beautiful way by providing graphical interface. In this example we simply provide --yesno to the whiptail and it shows these predefined options. The result will be returned as Yes or No which is evaluated in a if conditional statement.

By Using Whiptail

By Using Whiptail

 

How Prompt for Input in Bash Infografic

How Prompt for Input in Bash Infografic

How Prompt for Input in Bash Infografic

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)