Bash Script – Read User Input | bash script input arguments | bash read user input into variable

986 views Oct 22, 2023
publisher-humix monibe.com

To read user input in a Bash script, you can use the read command. The read command prompts the user for input and stores the input in a variable. The syntax for the read command is as follows: Bash read [-p prompt] variable Use code with caution. Learn more The -p flag specifies a prompt to display to the user. The variable is the name of the variable that will store the user's input. If you do not specify a prompt, the read command will simply display a blank line and wait for the user's input. Here is an example of how to use the read command to read user input: Bash #!/bin/bash # Prompt the user for their name read -p "Enter your name: " name # Print the user's name to the terminal