Don't fear the command line: Making it echo
Tags: beginners, codenewbie
Published: 2020-07-06 14:04:09

 The command line is used for navigating through files in our  filesystem and making changes to those files, if we wish to. However, the command line is so powerful that it can be used for more than that.
 When we run some specific commands in the command line we can receive a stream of output in the terminal. Practically we can type a string of words, press enter and see those words  return back to us!
In this post I'm going to show how  we can achieve that and output text on our screen.I'll also share some shortcuts to make typing easier and correct any mistakes we may make along the way.

![talk to computer](https://media.giphy.com/media/kRk8MQLBVwc0w/giphy.gif)

## The three standard streams

When  talking about standard streams in computing we are referring to the connected input and output communication channels and how they transfer data, in this case text, when a command is run. The distinction of standard has to do with where the input is being read from and where our output/error are being written to.
- **standard input(stdin)**  is the information that we input into the terminal. That is done mostly by typing on our keyboard.
- **standard output(stdout)** is the information displayed after our command is run, that is in most cases our terminal screen.
- **standard error(stderr)** is an error message when the process has failed.

Let's take this example:

```console
$ echo "Hello"
Hello
$
```
Here the echo command accepts the string "Hello" as *standard input(stdin)* , echoes the string "Hello" back to the terminal as *standard output(stdout)* and then returns another prompt($).

![echoing hello](https://media.giphy.com/media/KYIFQIusoEbaE/giphy.gif)

## Echoing
The echo command is how we get the shell to print messages back to us, as it prints our text to the terminal's screen. Echo is the command and the arguments it accepts are the string of characters that we want to print.For the string of words that we use, we can either use double quotes as we did in the example above, single quotes or no quotes at all.
If we are just using a few words it doesn't really matter which one we use as long as we are consistent.

![quotes](https://media.giphy.com/media/qs6ev2pm8g9dS/giphy.gif)

If we decide to use quotes, more often than not we may find ourselves in a sticky situation
```console
echo "so long, farewell
>
```
![break computer](https://media.giphy.com/media/bPCwGUF2sKjyE/giphy.gif)

It seems like we can't escape.
One way is to add the closing quote , or press `Control+C` . We can use the later in many cases when we are in trouble in the command line.

### Typing Hacks

When typing, there is a chance that we will make mistakes or that we'll want to make some changes along the way. Editing in the command line is fairly simple when we make full use of our keyboard.
- The up arrow ` ^ ` retrieves the previous command and when pressed again it moves further up the commands we have previously typed. The down arrow goes back down again.
- ` Control + A` get's us to the beginning of our line.
- ` Control + E` moves us to the end of our line.
- `Control + U ` deletes everything we have written so we can start fresh.
- Holding down our `Option` key and clicking on what we want to change, we manage to move the cursor to the location we wish to edit. That is an effective way of editing longer sentences.

![talking without knowing where it's going](https://media.giphy.com/media/zQj7gC1YQ1N9m/giphy.gif)
 
### Environmental Factors

So far we have seen that the  `echo` command has the same role as the print function in other programming languages. Besides printing strings to the screen like we talked about earlier, we can use `echo` to print the value of *environmental variables* to the standard output.
The *environment* is a working area that our shell builds every time we log in and is kept until we log out. The environment is defined by environmental variables.
One example of an environmental variable is :
```console
$ echo $SHELL
/bin/bash
$
```

- This shows us the user's shell ,in this case it's `bash`.
- Variables are set by using  `$` as a prefix.
- One thing to keep in mind with environment variables is that they are case sensitive and should have uppercase names. 

This an introduction and quick overview of input/output in the command line and some basic editing that can be done. We also scratched the surface of a different topic, that of using variables in the command line which I am looking forward to learning more about in the future.

![cat on screen](https://media.giphy.com/media/8CAFRDokyQkhi/giphy.gif)