Double-quote your variable to avoid getting Word-splitting by shell
printf "$test"
Moreover, the general syntax for printf
like C
would be to have
printf <FORMAT> <ARGUMENTS...>
The text format is given in <FORMAT>
, while all arguments the format string may point to are given after that, here, indicated by <ARGUMENTS…>
.
The problem you are seeing is because an unquoted variable in bash
invokes the word-splitting. This means that the variable is split on whitespace (or whatever the special variable $IFS
has been set to) and each resulting word is used as a glob (it will expand to match any matching file names). Your problem is with because of the splitting part.