All Posts programming print given arguments | GNU Echo

print given arguments | GNU Echo

· 159 words · 1 minute read

echo is a GNU util that prints given arguments.

Print a text message. Note: quotes are optional:

echo "Hello World"

Print a message with environment variables:

echo "My path is $PATH"

Print a message without the trailing newline:

echo -n "Hello World"

Append a message to the file:

echo "Hello World" >> file.txt

Enable interpretation of backslash escapes (special characters):

echo -e "Column 1\tColumn 2"

Print the exit status of the last executed command (Note: In Windows Command Prompt and PowerShell the equivalent commands are echo %errorlevel% and $lastexitcode respectively):

echo $?

For more information, check out the documentation on GNU utils website: https://www.gnu.org/software/coreutils/manual/html_node/echo-invocation.html .

I hope you enjoyed reading this post as much as I enjoyed writing it. If you know a person who can benefit from this information, send them a link of this post. If you want to get notified about new posts, follow me on YouTube , Twitter (x) , LinkedIn , and GitHub .