0
0
Bash Scriptingscripting~10 mins

Why input makes scripts interactive in Bash Scripting - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read user input into a variable named 'name'.

Bash Scripting
read [1]
Drag options to blanks, or click blank then click option'
Aname
Binput
Cvar
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'input' as the variable name instead of 'name'.
Forgetting to specify a variable after 'read'.
2fill in blank
medium

Complete the code to prompt the user with 'Enter your age:' before reading input.

Bash Scripting
read -p "Enter your age: " [1]
Drag options to blanks, or click blank then click option'
Aage
Binput
Cuser
Dvar
Attempts:
3 left
💡 Hint
Common Mistakes
Not using the -p option to show a prompt.
Using a variable name unrelated to the data.
3fill in blank
hard

Fix the error in the code to correctly read input into 'color'.

Bash Scripting
read [1]
Drag options to blanks, or click blank then click option'
Aread
B$color
Ccolor
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Using $ before the variable name in the read command.
Trying to use 'read' as a variable name.
4fill in blank
hard

Fill both blanks to read input into 'username' and then print a greeting.

Bash Scripting
read [1]
echo "Hello, $[2]!"
Drag options to blanks, or click blank then click option'
Ausername
Buser
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for reading and printing.
Forgetting the $ sign when printing the variable.
5fill in blank
hard

Fill all three blanks to read a number, check if it is greater than 10, and print a message.

Bash Scripting
read [1]
if [ $[2] [3] 10 ]; then
  echo "Number is greater than 10"
fi
Drag options to blanks, or click blank then click option'
Anumber
C-gt
D-lt
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for reading and checking.
Using the wrong comparison operator.
Forgetting the $ sign when referencing the variable.