Reputation: 3331
How to escape special character? I want to print minus character.
echo \-; # Output:-
echo '-n'; #Output: nothing!
Upvotes: 4
Views: 68
Reputation: 123458
You are attempting to print -n
which is interpreted as an argument to disable printing of the trailing newline.
Here printf
comes handy:
$ printf "%s" "-n"
-n
If you want a newline after n
,
$ printf "%s\n" "-n"
-n
An ugly way using echo
would be to use the octal value for the hyphen, i.e. -
,
$ echo -e '\055n'
-n
The -e
argument enables interpretation of backslash escapes.
Upvotes: 5