mirror of
https://codeberg.org/Mo8it/How_To_Linux.git
synced 2024-11-21 19:18:02 +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
|
RIGHT_ANSWER=1
|
||||||
|
|
||||||
# The option -n does not print a new line at the end
|
# `-p` Sets the prompt message
|
||||||
echo -n "Enter a number: "
|
read -p "Enter a number: " ANSWER
|
||||||
read ANSWER
|
|
||||||
|
|
||||||
if [ $ANSWER == $RIGHT_ANSWER ]
|
if [ $ANSWER == $RIGHT_ANSWER ]
|
||||||
then
|
then
|
||||||
|
@ -235,9 +234,8 @@ In a script, you can ask for user input.
|
||||||
To do so, you can use the command `read`.
|
To do so, you can use the command `read`.
|
||||||
|
|
||||||
In our first Bash script, we use `read` to ask the user for his answer.
|
In our first Bash script, we use `read` to ask the user for his answer.
|
||||||
The input is then saved in the variable `ANSWER`.
|
The input is then saved in the variable `ANSWER` (you can also choose a different name for this variable).
|
||||||
You can 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.
|
||||||
After the line with `read`, you can use the variable storing the input as a normal variable.
|
|
||||||
|
|
||||||
## Arguments
|
## Arguments
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue