To take a single line of input from the user in a shell script, you can use the read
command. The read
command reads a line of input from the user and stores it in a variable.
Here's an example of how to use the read
command to take a single line of input from the user in a shell script:
# Prompt the user for input echo "Enter a line of text:" # Read the input and store it in the variable "input" read input # Print the input echo "You entered: $input"
This script will prompt the user to enter a line of text, read the input, and then print the input to the terminal.
It's important to note that the read
command reads a single line of input, regardless of how many words or characters the line contains. If you need to read multiple lines of input from the user, you can use a loop to repeatedly prompt the user for input. Consult the read
documentation and online resources for more information on how to use the read
command in a shell script.