Skip to content

echo Command

The echo command outputs the arguments it receives to the screen (by default).

echo command example
ali@gnuadmin:~$ echo gnuadm.in
gnuadm.in

At first glance, you may think "What good is this going to do for me?" but this command can have many different uses:

  • Output to the user in shell scripts
  • To print a variable or an output containing variables
  • Printing the newly created values to a file
  • Emptying a file
writing variables with eco
ali@gnuadmin:~$ echo $USER
ali
ali@gnuadmin:~$ echo $HOME
/home/ali
ali@gnuadmin:~$ echo $SHELL
/bin/bash
ali@gnuadmin:~$ echo "$SHELL shell'ini kullanan $USER kullanıcısının ev dizini: $HOME"
/bin/bash shell'ini kullanan ali kullanıcısının ev dizini: /home/ali
writing to a file with echo
ali@gnuadmin:~$ echo "$SHELL shell'ini kullanan $USER kullanıcısının ev dizini: $HOME" > test
ali@gnuadmin:~$ cat test 
/bin/bash shell'ini kullanan ali kullanıcısının ev dizini: /home/ali
ali@gnuadmin:~$ echo "">test
ali@gnuadmin:~$ cat test

echo Single Quote and Double Quote Difference

If you enclose the arguments of the echo command in single quotes, the arguments you type will be written as they are. Let's examine the output when trying to print the value of a variable:

single quote and double quote difference
ali@gnuadmin:~$ echo $PWD
/home/ali
ali@gnuadmin:~$ echo "$PWD"
/home/ali
ali@gnuadmin:~$ echo '$PWD'
$PWD

You can visit here to get more detailed information with the echo command and to see usage examples in scripts.