Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

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.

like image 911
Van Assassin Avatar asked Nov 22 '25 08:11

Van Assassin


1 Answers

Add --:

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

Use -- to signify the end of the options.

like image 137
Cyrus Avatar answered Nov 24 '25 22:11

Cyrus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!