3

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.

1 Answer 1

7

Add --:

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

Use -- to signify the end of the options.

Sign up to request clarification or add additional context in comments.

1 Comment

Shouldn't that be printf -- "$format" 1? Or does Bash manage to treat it as a built-in command with special handling for string arguments?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.