Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get $(/bin/printf -6) to return -6 and not think -6 is an option

I have a bash shell script which has the line:

g=$(/bin/printf ${i})

when ${i} contains something like -6, printf thinks its being passed an option. It does not recognize the option so produces an error.

if wrap ${i} in quotes, printf still thinks its being passed an option.

g=$(/bin/printf "${i}")

if I escape the quotes, variable $g then holds "-6" which is not what I want either.

g=$(/bin/printf \"${i}\") 

Is there away to escape the dash (-).

printf is a BusyBox app

like image 845
Andrew Avatar asked Dec 01 '22 11:12

Andrew


1 Answers

Most GNU programs support using -- as a delimiter to tell the program that all further arguments are not options. For instance

$ printf -- -6
-6
like image 144
Jack Lloyd Avatar answered Apr 08 '23 15:04

Jack Lloyd