Creating and Reading Files

The echo command takes text and prints it back to the screen. At the prompt, type the following command:

 $ ​​echo​​ ​​Hello​​ ​​there

You’ll see the text you entered printed back to you. You’ll use echo in scripts you write to display instructions or output to users. But you can also use it to insert text into files if you combine it with a feature called redirection.

Let’s create a text file in your Desktop directory that contains the text “Hello”. You’ll call this file greetings.txt. At the prompt, type:

 $ ​​echo​​ ​​Hello​​ ​​>​​ ​​greetings.txt

When you press the Enter key you won’t see any visual feedback because the output of the echo command was redirected to the file you specified. If you look at your ...

Get Small, Sharp Software Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.