Here Document in Shell

Level 480 keystrokes

A here document passes the lines up to EOF to cat as input; here they are written to config.txt. Variables such as $USER are expanded (the output shows user=developer).

Shell code

# << EOF feeds the following lines, up to EOF, to cat as input
# > config.txt saves the text; $USER is replaced by the user name
1cat << EOF > config.txt
2server=localhost
3port=8080
4user=$USER
5EOF
# Show the generated file
6cat config.txt

Output

server=localhost
port=8080
user=developer
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.

  • =× 3
  • .× 2
  • <× 2
  • >× 1
  • $× 1

More Shell examples at level 4

← Shell typing practice