Here is an example of a script that prompts the user for a password and stores it in a variable:
#!/bin/bash # Prompt the user for a password read -s -p "Enter password: " password # Print the password echo "Your password is: $password"
The read
command is used to prompt the user for input, and the -s
option specifies that the input should be read in silent mode (i.e., it will not be displayed on the screen). The -p
option specifies the prompt string to be displayed to the user.
In this example, the user will be prompted to enter a password, and the password will be stored in the password
variable. The password will not be displayed on the screen as it is typed.
After the user enters the password and hits Enter, the script will print the password stored in the password
variable.
Note that this script is just an example and should not be used in a production environment, as it does not provide any security measures to protect the password. In a real-world scenario, you would need to use appropriate measures to secure the password, such as hashing or encrypting it.