echo
display a line of text
Synopsis
echo
[SHORT-OPTION]... [STRING]...
echo LONG-OPTION
add an example, a script, a trick and tips
examples
source
equivalent "echo on" for linux?
Use bash -v
.
This is the script:
#!/bin/bash -v
echo "Hello, World" | sed 's|Hello|Goodbye|'
echo "Done."
This is the output:
#!/bin/bash -v
echo "Hello, World" | sed 's|Hello|Goodbye|'
Goodbye, World
echo "Done."
Done.
Unfortunately, there is no special marker like PS4
for printing expanded commands. You could combine both though to
quickly identify commands:
#!/bin/bash -vx
echo "Hello, World" | sed 's|Hello|Goodbye|'
+ echo 'Hello, World'
+ sed 's|Hello|Goodbye|'
Goodbye, World
echo "Done."
+ echo Done.
Done.
source
Can a string be inserted at a specific line in a file from the CLI?
Here's some perl solutions:
perl -p -i -e 'print "Hey\n" if /Hi/' filename
or
perl -p -i -e 'print "Hey\n" if $. == 4' filename
or
perl -n -i -e 'print; print "Hey\n" if /Hello/' filename
source
Use xargs to send requests to the same server in parallel with netcat
Use echo -n
or you will get 5 connections instead
four, one of them with no data. If in the server this is not
checked, maybe it is causing your problem.
echo -n A,B,C,D | xargs -d, -I{} -P 4 -n 1 echo {} | nc localhost 7000
Moreover, using a netcat as listening server, it appears to work
right:
zhen@sydow:~$ nc -l 7000
A
D
B
C
And also it seems to be parallel, I see out-of-order echo.
source
How to escape newline in the commandline?
printf "%s\n%s\n%s\n" "Line 1", "Line 2", "Line 3"
source
In a for loop, how do I echo only the current file on a single(updating) line instead of EVERY file which will produce a list?
Just change the echo line to this:
echo -ne "\r * $file > $newf "
The spaces on the end clear old output from the line.
source
How to get GNU-Screen Command in Linux to echo locally
My mistake, I had an open screen session and didn't know how to
reconnect to it, so I forced a new session by sudo
screen
and that session was extremely messed up (corrupt
characters) and didn't echo 90% of the characters. I was able to
reconnect to that session and all was well.
source
How does `echo` work in this context?: `externalip() { curl http://ipecho.net/plain; echo; }`
Why does it echo the response body of the previous
curl
command?
A classic loaded question.
It doesn't do any such thing. The curl
command
outputs an IP address without a trailing newline. The
echo
command supplies the newline. It's that simple.
Whether
echo "$(curl -s http://ipecho.net/plain)"
is more straightforward than
curl http://ipecho.net/plain ; echo
is a matter of taste to some extent. It's worth noting, however,
that $()
is not available in the Bourne (not to be
confused with the Bourne Again) shell nor in the C shells,
whereas pretty much all shells can execute two plain commands in
sequence separated by a semi-colon. That even includes
csh
and fish
. ☺
source
space at the end of variable is killed on output
As ever so often, the answer lies in quoting.
echo -n $TEST > text
This will get expanded to:
echo -n test > text
Note the two spaces after test
. The only arguments
echo
sees are -n
and test
.
Nothing else. The space gets lost here. To keep it, you need to
double-quote $TEST
:
echo -n "$TEST" > text
See also: Quotes and escaping on the Bash Hackers wiki.
source
How to input text in a file in a specific line?
sed -i 's/command=/&sudo /' file
explanation: examining the file line-by-line, replace the text
"command=" with "command=sudo ". The &
in the
replacement string will be whatever is matched from the left-hand
side.
description
Echo the
STRING(s) to standard output.
-n
do not output the trailing newline
-e
enable interpretation of backslash escapes
-E
disable interpretation of backslash escapes
(default)
--help
display this help and exit
--version
output version information and
exit
If
-e is in effect, the following sequences are
recognized:
\\
backslash
\a
alert (BEL)
\b
backspace
\c
produce no further output
\e
escape
\f
form feed
\n
new line
\r
carriage return
\t
horizontal tab
\v
vertical tab
\0NNN
byte with octal value NNN (1 to 3 digits)
\xHH
byte with hexadecimal value HH (1 to 2 digits)
NOTE: your
shell may have its own version of echo, which usually
supersedes the version described here. Please refer to your
shell’s documentation for details about the options it
supports.
copyright
Copyright © 2012 Free Software Foundation, Inc. License GPLv3+:
GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute
it. There is NO WARRANTY, to the extent permitted by law.
reporting bugs
Report echo bugs to bug-coreutils[:at:]gnu[:dot:]org
GNU coreutils home page:
<http://www.gnu.org/software/coreutils/>
General help using GNU software:
<http://www.gnu.org/gethelp/>
Report echo translation bugs to
<http://translationproject.org/team/>
see also
The full
documentation for echo is maintained as a Texinfo
manual. If the info and echo programs are
properly installed at your site, the command
info
coreutils 'echo invocation'
should give you
access to the complete manual.
author
Written by
Brian Fox and Chet Ramey.