>>
redirects the output of the command on its left hand side to the end of the file on the right-hand side.
So,
echo '* - nofile 65535' >> /etc/security/limits.conf
will append * - nofile 65535
to the end of the /etc/security/limits.conf
file, instead of printing * - nofile 65535
on the screen.
If you instead had
echo '* - nofile 65535' > /etc/security/limits.conf
(note the >>
replaced by >
), everything already present in /etc/security/limits.conf
would have been replaced by * - nofile 65535
, and not appended.
You may also like to read this question:
If you open up a bash
prompt and type in an echo
command, that uses a shell builtin rather than running /bin/echo
. The reasons it is still important for /bin/echo
to exist are:
- You're not always using a shell. Under a variety of circumstances, you run an executable directly and not through a shell.
- At least in theory, some shells don't have an
echo
builtin. This is not actually required.
To expand on #1, suppose you wanted to move all the regular files whose names started with abc
anywhere in src
to dest
. There are several ways to do that but one of them is:
find src -name 'abc*' -type f -exec mv -nv {} dest/ \;
But suppose, rather than just running that, you want to see every command that will be run first. Well, then you can prepend echo
to the command, just as you might in other contexts:
find src -name 'abc*' -type f -exec echo mv -nv {} dest/ \;
But find
doesn't use a shell. That runs /bin/echo
.
Besides find
with -exec
or -execdir
, the /bin/echo
executable will be called by other programs that themselves run programs but not through a shell. This happens with the xargs
command (which is related to find
), as well as in a number of other contexts, such as the Exec=
line of a .desktop
file. Another example is when you run sudo echo
, which can be handy for testing if sudo
is working.
Similarly, some shells have a printf
builtin but /usr/bin/printf
also exists.
A less common possible reason you might deliberately use /bin/echo
is if you were relying on the differences between it and the echo
command provided by your shell. man echo
documents /bin/echo
; help echo
in bash
documents the bash
builtin. echo
is not very portable, because different implementations--both across operating systems and across shells on the same operating system--support different options (e.g., -e
) and differ in their treatment of backslashes. Of course, it's better to avoid relying on such details, and use printf
instead, which is far more portable.
In bash
, you can make the type
builtin show /bin/echo
as well--assuming /bin
is in your $PATH
as it always should be--by passing it the -a
flag:
$ type -a echo
echo is a shell builtin
echo is /bin/echo
Best Answer
Convention.
$$
: Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the invoking shell, not the subshell (see the link to the manual below).Very useful when coding software. And it can be used as a crude (
mktemp
would be the better method) way of creating temp files1
$
has no special meaning so it gives you what echo always does: return it.There is a manual page dedicated to this (3.4.2 Special Parameters).