Linux Reader
Access files and folders on Ext, UFS, HFS, ReiserFS, or APFS file systems from Windows

Pew Pew madafakas!

Access files and folders on Ext, UFS, HFS, ReiserFS, or APFS file systems from Windows
Last updated: Sep 06, 2021

Bash Script: How to Perform User Input

Here you will find out:

  • how to use Bash script user input
  • examples of shell script input
  • when DiskInternals can help you

Are you ready? Let's read!

How to use Bash script user input

Scripts are nothing more than commands (often several consecutive commands), which are necessary for reading and subsequent execution of the command-line program - bash. The contents of one script must contain certain commands, as well as the program that is involved in their execution. You can completely omit the program, and then the user interpreter will be used by default.

Here is an example of a bash script input:

 bash script input syntax

Example 1. Input User's Name

The user name is entered using the read command and then stored in variables.

This is relevant since Bash scripts are often entered without saving variables. And without variables, a programming language is worth nothing. The command looks like this: read var1. And for a better understanding, you need an example:

 read input users name

At the same time: read varname - activates the main command and creates a variable.

The symbol of backslash for verification is required.

Example 2. Name & Password

Here, let's understand an example of how to use the command read in Bash to create a name and password by entering them from the keyboard and, at the same time, give hints to the user so that they understand what data is being requested from them.

input users name and password

For reference:

-p - identifies the encrypted user password (this is used for the convenience of the user so that he knows what he is entering; i.e., a hint in the form of text).

-s - allows you to secretly enter passwords from the keyboard.

In this case, you can write -sp, or -s-p - the Command read will work the same.

Example 3. Inputs of multiple variables

Shell script user input can not only be with one variable, but also with several. This is already a higher level of programming, but many people use several variables, as it is convenient and practical.

Here is an example of such data entry:

Example of input of multiple variables

Example 4. Input with limits

You can limit the input of commands by time at your discretion.

To do this, together with the command to read, you need to type the characters -t. It should be borne in mind that the unit of time is 1 second. Here's how it looks with an example:

Example of input with limits

Here, the limit is set to 4 seconds, and so, you can write any value.

DiskInternals Linux Reader is a well-equipped tool for users with dual-boot or virtual machines on their computers

This is very useful if you use Linux and Windows on the same computer. At the same time, you need information from your Ext4, UFS2, or ZFS partition - this utility can help access these files.

This is definitely a useful and necessary tool that supports various file systems (Ext2, Ext3, Ext4, ReiserFS, HFS, HFS +, NTFS, FAT, exFAT.). In addition, it is possible to extract the largest file sizes. DiskInternals Linux Reader is notable for its ease of use, despite the most important tasks.

Related articles

FREE DOWNLOADVer 4.21, WinUpgrade to PROFrom $29.95

Please rate this article.
4.34 reviews