From 8b2db86efc080d0f89b3e9e3816ca66930de319c Mon Sep 17 00:00:00 2001 From: mo8it Date: Fri, 18 Aug 2023 01:34:05 +0200 Subject: [PATCH] Use prompt with read --- src/day_4/shell_scripting.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/day_4/shell_scripting.md b/src/day_4/shell_scripting.md index c4a6c9c..3441945 100644 --- a/src/day_4/shell_scripting.md +++ b/src/day_4/shell_scripting.md @@ -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