Read User Input in Shell

Level 363 keystrokes

read command gets input from the user and stores it in a variable.

Shell code

# -p shows the prompt; the typed line is stored in username (bash)
# read -r would also keep backslashes exactly as typed
1read -p "Enter your name: " username
# If Alice was typed, prints: Welcome, Alice!
2echo "Welcome, $username!"

Output

Enter your name: Alice
Welcome, Alice!
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Shell code and how often they appear.

  • "× 4
  • -× 1
  • ,× 1
  • :× 1
  • !× 1
  • $× 1

More Shell examples at level 3

← Shell typing practice