Forrest logo
back to the read tool

read:tldr:3e0c8

read: Store each of the next lines you enter as values of an array.
$ read -a ${array}
try on your machine

This command is used in shell scripting to read input from the user and store it in an array.

  • read: This is a built-in command in shell scripting that reads a line from the standard input (usually user input), divides it into fields (by default separated by whitespace), and assigns the fields to variables.
  • -a: This option is used to specify that the read command should populate an array rather than individual variables.
  • ${array}: This is the name of the array variable where the read command will store the input. It could be any valid variable name of your choice.

When this command is executed, it will prompt the user to input some values. Each value entered will be assigned to consecutive elements of the array. For example, if the user enters "apple", "banana", and "orange" as input, those values will be stored respectively as ${array[0]}, ${array[1]}, and ${array[2]}.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the read tool