Forrest logo
tool overview
On this page you find all important commands for the CLI tool read. If the command you are looking for is missing please ask our AI.

read

The "read" command line tool is used to read a line of input from the user or from a file. It allows the user to enter data interactively or to read input from files in the terminal console.

When used without any options, the "read" command simply reads a line of input from the user and assigns it to a variable. For example, the command "read name" will read a line of text input from the user and store it in the variable called "name".

Additionally, you can provide options to modify the behavior of the "read" command. Some commonly used options include:

  • "-p" option: Used to prompt the user with a custom message. For example, "read -p 'Enter your name: ' name" will display the message "Enter your name: " before reading the user's input.

  • "-r" option: By default, the "read" command interprets backslashes ("\") as escape characters, but the "-r" option can be used to treat them as literal characters instead.

  • "-a" option: This option is used to read multiple inputs into an array. For example, "read -a numbers" will read multiple space-separated inputs from the user and store them in the array called "numbers".

In addition to reading input from the user, the "read" command can also read input from files by specifying the file name as an argument. It will read each line of the file and assign it to the specified variable.

The "read" command is a versatile tool for capturing user input or reading input from files, making it useful for various tasks in shell scripting and automation.

List of commands for read:

  • coproc:tldr:4917b coproc: Read from a specific coprocess `stdout`.
    $ read ${variable} <&"$${{name}[0]}"
    try on your machine
    explain this command
  • read:tldr:3e0c8 read: Store each of the next lines you enter as values of an array.
    $ read -a ${array}
    try on your machine
    explain this command
  • read:tldr:48f7d read: Specify the number of maximum characters to be read.
    $ read -n ${character_count} ${variable}
    try on your machine
    explain this command
  • read:tldr:60397 read: Do not let backslash (\\) act as an escape character.
    $ read -r ${variable}
    try on your machine
    explain this command
  • read:tldr:7ab7f read: Store data that you type from the keyboard.
    $ read ${variable}
    try on your machine
    explain this command
  • read:tldr:ba9b7 read: Do not echo typed characters (silent mode).
    $ read -s ${variable}
    try on your machine
    explain this command
  • read:tldr:c1469 read: Use a specific character as a delimiter instead of a new line.
    $ read -d ${new_delimiter} ${variable}
    try on your machine
    explain this command
  • read:tldr:c1b5b read: Display a prompt before the input.
    $ read -p "${Enter your input here: }" ${variable}
    try on your machine
    explain this command
tool overview