The backslash stops the shell from misinterpreting the next character if it has special meaning to the shell. The following characters may have special meaning: & * = ^ $ ` " | ?.
Issuing the echo command with an * causes a listing of the whole current directory in a squashed up format, instead of echoing just the asterisk.
$ echo *
conf.linuxconf conf.modules cron.daily cron.hourly cron.monthly
cron.weekly crontab csh.cshrc default dosemu.conf dosemu.users exports
fdprm fstab gettydefs gpm-root.c
onf group group- host.conf hosts hosts.allow hosts.deny httpd inetd
...
To disable the special meaning of the asterisk, use a backslash.
$ echo *
*
The same thing goes for the $$ command which the shell interprets as your current PID (process ID number). To disable it and just echo the $$ put a backslash in front.
$ echo $$
284
$ echo $$
$$
To include octal characters when echoing, you must precede them with the backslash, otherwise the shell will just think they are ordinary numbers.
$ echo " This is a copyright 251 sign"
This is a copyright 251 sign
$ echo " This is a copyright 251 sign"
This is a copyright © sign
If it’s Linux then . . .Remember to use the ‘-e’ for control characters. $ echo -e "This is a copyright 251 sign"
This is a copyright © sign
|
When using the command expr, if you try to multiply using the * it will return an error. Put a backslash before the * sign, and this will work.
$ expr 12 * 12
expr: syntax error
$expr12* 12
144
To include any of the metacharacters within an echo statement, you must escape them with a backslash. In the following example, the price $19.99 is to be displayed, but because we have not escaped it the shell, the shell will treat it differently.
$ echo "That video looks a good price for $19.99"
That video looks a good price for 9.99
Now if we escape the dollar sign we get a better result.
$ echo "That video looks a good price for $19.99"
That video looks a good price for $19.99
3.133.137.169