mirror of
https://codeberg.org/Mo8it/How_To_Linux.git
synced 2024-11-24 09:51:36 +00:00
Use prompt with read
This commit is contained in:
parent
7564366d53
commit
8b2db86efc
1 changed files with 4 additions and 6 deletions
|
@ -26,9 +26,8 @@ echo "3. Mac"
|
|||
|
||||
RIGHT_ANSWER=1
|
||||
|
||||
# The option -n does not print a new line at the end
|
||||
echo -n "Enter a number: "
|
||||
read ANSWER
|
||||
# `-p` Sets the prompt message
|
||||
read -p "Enter a number: " ANSWER
|
||||
|
||||
if [ $ANSWER == $RIGHT_ANSWER ]
|
||||
then
|
||||
|
@ -235,9 +234,8 @@ In a script, you can ask for user input.
|
|||
To do so, you can use the command `read`.
|
||||
|
||||
In our first Bash script, we use `read` to ask the user for his answer.
|
||||
The input is then saved in the variable `ANSWER`.
|
||||
You can choose a different name for this variable.
|
||||
After the line with `read`, you can use the variable storing the input as a normal variable.
|
||||
The input is then saved in the variable `ANSWER` (you can also choose a different name for this variable).
|
||||
After the line with `read`, you can use the variable storing the input just like any other variable.
|
||||
|
||||
## Arguments
|
||||
|
||||
|
|
Loading…
Reference in a new issue