echo -e
and echo $'...'
are both similar in that they support the following escape sequences:
\a alert (bell)
\b backspace
\e
\E an escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\0nnn the eight-bit character whose value is the octal value nnn (zero to three octal digits)
\xHH the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
\uHHHH the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value HHHH (one to four hex digits)
\UHHHHHHHH
the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value HHHHHHHH (one to eight hex digits)
They do have differences. In addition to the above, echo -e
supports:
\c suppress further output
\0nnn the eight-bit character whose value is the octal value nnn (zero to three octal digits)
By contrast, $'....'
supports:
\' single quote
\" double quote
\nnn the eight-bit character whose value is the octal value nnn (one to three digits)
\cx a control-x character
Observe that, between the two, the \c
extensions are incompatible:
$ echo -e 'start\n\cIstop'
start
$ echo $'start\n\cIstop'
start
stop
For echo -e
above, \c
suppresses further output, thereby ignoring the Istop
. By contrast, for $'...'
, the \cI
is interpreted as a tab.
The visually-similar form: $"..."
By contrast with $'...'
, the function of $"..."
is quite different. It will cause the string it contains to be translated according to the current locale.
The echo -e
controversy
echo -e
is not universally supported by shells and many regard the -e
option as a design mistake. Observe:
$ ls
-e -n
$ echo *
$ printf "%s\n" *
-e
-n
As you can see, if what you are printing with echo
starts with a dash, the results can be unexpected. Unless you are sure that the first string that you will print with echo
does not start with a dash, you are likely better off using printf
.
For these reasons, the POSIX standard concludes:
New applications are encouraged to use printf instead of echo.
Chet Ramey, who has maintained bash
for the last 22 years, agrees:
[N]ew code should use printf.
In short, if the screen shows a dollar sign ($
) or hash (#
) on the left of the blinking cursor, you are in a command-line environment.
$
, #
, %
symbols indicate the user account type you are logged in to.
- Dollar sign (
$
) means you are a normal user.
- hash (
#
) means you are the system administrator (root).
- In the C shell, the prompt ends with a percentage sign (
%
).
There are differences on prompts in different Unix or GNU/Linux distributions because of their default settings. For example, the prompt of Debian/Ubuntu is guest@linux:~$
, the one of Fedora/CentOS/RedHat is [guest@linux ~]$
and the one of SuSE Linux/OpenSUSE is guest@linux:~>
. In general, the prompt usually show the login user name, machine hostname, and current working directory and ended with a dollar ($), percentage (%), or hash (#) sign.
guest@linux:~$
guest
- username: the user account you are logged in to.
linux
- machine hostname: the machine you are operating.
~
- current working directory: the directory you are in. Tilde (~
) means home directory, i.e. the default directory when first logging in.
Reference: wiki.debian.org.hk/w/Basic_Command_Line
Best Answer
From
sort
info page, sort-g
is explained by thesesort -n
is the natural sort we usually expectCheck Steeldriver's answer for a better explanation.