How can I use a dash in printf
string?
x=xxx
printf -v args "-x=%s" "$x"
printf "$var"
But it gives an error:
./tmp.sh: line 2: printf: -x: invalid option
printf: usage: printf [-v var] format [arguments]
I know that it's because printf
interprets -x
as an option, but how to overcome it?
I use printf
to create a string that will correspond to command line arguments like -x=xxx -y=yyy -z=zzz
. Then I want to call a tool like
eval $tool args
printf
at all, as you should be building an array of arguments to pass totool
:foo=(-x xxx -y yyy); tool "${foo[@]}"
– chepner Jul 25 '18 at 14:02