09. echo_command - muneeb-mbytes/linux_course GitHub Wiki
echo command
Echo is a simple command that simply prints its arguments on the terminal.
It is mostly used in files to output status text to the terminal screen.
echo command and its variations
The below figure shows echo command and its options.
Figure 1: Echo command and its variations
echo command cheat sheet
Sr No. | echo commands with different options | description |
---|---|---|
1 | echo "string" | Display string |
2 | echo -e "string1\tstring2 | Display string with horizontal tab spaces |
3 | echo -e "string1\vstring2 | Display string with vertical tab spaces |
4 | echo -e "string1\bstring2 | Display string without spaces |
5 | echo -e "string1\nstring2 | Display strings in new line |
6 | echo $USER | Display username |
Note : This commands work in bash. In tcsh also echo "string" works.
echo "string"
Syntax: echo "string"
Example: echo "Manipal"
This command displays the string 'Manipal' in output terminal.
Below figure shows the output of echo "Manipal".
Figure 2: Echo command actual output
The below figure shows that output of echo command and its actual output.
GIF.1 : Echo GIF
Link to GitHub lab :https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/echo_commands/echo.csh
echo -e "string1\tstring2"
Syntax: echo "string1\tstring2"
Example: echo "Hello\tWorld"
The '\t' command is used to give horizontal tab spaces between string1 and string2.
Below figure shows the output of "Hello\tWorld"
Fig 2: output of "Hello\tWorld"
echo -e "string1\vstring2"
Syntax: echo "string1\vstring2"
Example: echo "Hello\vWorld"
The '\v' command is used to give vertical tab spaces between string1 and string2.
Below figure shows the output of echo "Hello\vWorld".
Fig 3 : output of echo "Hello\vWorld
echo -e "string1\bstring2"
Syntax: echo "string1\bstring2"
Example: echo "Hello\bWorld"
The '\b' command displays without spaces between string1 and string2. The output shows that '\b' removes the spaces between two strings.
Below figure shows the output of echo "Hello\bWorld".
Fig 4: output of echo "Hello\bWorld"
echo -e "string1\nstring2"
Syntax: echo "string1\nstring2"
Example: echo "Hello\nWorld"
This command \n display the string1 and string2 in two lines.'\n' command display string2 in new line.
Below figure shows the output of echo "Hello\nWorld".
Fig 5:Output of echo "Hello\nWorld"
echo $USER
Syntax: echo $USER
Example: echo $USER
This command $USER displays the current username.
Fig 6: Output of echo $USER
Multiple echo outputs in one line
Syntax:
echo [option] [string] \
Example:
echo -e "hello \
world \
Good morning"
We can combine multiple echo outputs in one line using the above syntax. '-e ' option asks the echo command to interpret the escape characters.
The output shows the combined outputs of echo command. '' command is used to separate the string in two lines.
Below figure shows the output of echo -e "hello \
world \
Good morning"
Fig 7: Multiple echo outputs in one line
To learn head command: https://github.com/muneeb-mbytes/linux_course/wiki/10.-head-command