Session and utilities

The read command

Reads a line from the input and stores it in a variable. It is how you ask the user for data in a script.

Syntax

read [-p mensaje] variable

Most useful options

-pShows a prompt before reading
-sDoes not show what is typed (passwords)

Copy-ready examples

$ read NOMBRERead from a pipe

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • In a pipe, read runs in a subshell: the variable may not stay in your session.

Related commands

FAQ

How do I ask for a password?

With read -s, so it is not visible while typing.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course