Reputation: 503
Today I was testing a script and for some reason I needed to print -n
to the console.
I tried echo -n
, which of course just echos without a new line.
I tried echo "-n"
, which does the same.
Then I tried assigning to a variable:
str="-n"
. Of course echo $str
and echo "$str"
do nothing.
How would you echo exactly -n
?
Upvotes: 0
Views: 2225
Reputation: 1
You could escape (\
) both of those characters, telling your shell to read them both as literal characters.
Running echo \-\n
gives me -n
as output.
Upvotes: 0