Lukap
Lukap

Reputation: 31963

echoing in shell -n doesn't get printed the right thing

I know that this is some kind of special character issue but I do not know how to solve it.

I type in console

echo "-n"

and nothing get printed :(

I also tried with

echo -e "-n" 

to execute the special characters (the one escaped from sequence) but again nothing happend

how can I print "-n" ?

Upvotes: 9

Views: 287

Answers (2)

Fritz G. Mehner
Fritz G. Mehner

Reputation: 17188

Try

printf "%s\n" -n

or

printf "%s\n" '-n'

Upvotes: 11

NPE
NPE

Reputation: 500287

Here is one way:

aix@aix:~$ echo -e '\x2dn'
-n

It escapes the - as \x2d.

A more verbose way is to print the two characters separately:

aix@aix:~$ echo -n -; echo n
-n

Here, the -n instructs the first echo to not print a newline; it is not related to the -n being printed. :)

Upvotes: 5

Related Questions