Quantcast
Channel: Escaping hyphens (--) with printf in bash - Super User
Viewing all articles
Browse latest Browse all 2

Escaping hyphens (--) with printf in bash

$
0
0

I have the following line:

printf "---- %.55s\n""$1 --------------"

When I run this under bash I get the following error:

printf: --: invalid option printf: usage: printf [-v var] format [arguments]

This is because (I think) printf interprets the string "----" as the beginning of an argument. I have tried to escape this using "\" like so:

printf "\---- %.55s\n""$1 --------------"

The following is the result:

\---- content of $1 -------

As you can see the "\" became part of the output which is not what I want.

So the question is, how can i persuade printf that I am not trying to pass a long argument?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images