Van Assassin
Van Assassin

Reputation: 59

Bash using --- (triple dash) at start of format string for printf

I have a stored string "--- RE%d ---\n" in a format variable for printf, but when I use it like:

format="--- RE%d ---\n"
printf $format 1

printf treats -- like I want to use some option. When I put anything before ---, it works fine. Is there a way to make printf to print just: --- RE1 ---? I was using \r as 1st character, but it is shown at script output as ^H.

Upvotes: 3

Views: 1052

Answers (1)

Cyrus
Cyrus

Reputation: 88583

Add --:

format="--- RE%d ---\n"
printf -- "$format" 1

Use -- to signify the end of the options.

Upvotes: 7

Related Questions