Avoiding a shell parameter such as '-n'

How to avoid a special character? I want to print a negative symbol.

echo \-; # Output:-
echo '-n'; #Output: nothing!
+4
source share
1 answer

You are trying to print -n, which is interpreted as an argument, to disable printing of the trailing newline.

printfSuitable here :

$ printf "%s" "-n"
-n

If you want a new line after n,

$ printf "%s\n" "-n"
-n

An ugly way using echowould be to use the octal value for a hyphen, that is -,

$ echo -e '\055n'
-n

The argument -eallows you to interpret escape backslashes.

+5
source

Source: https://habr.com/ru/post/1539907/


All Articles