Is there a way to printf $@ verbatim?

Your positional parameters do not contain any double quotes in your example:

./script1 a "bc d"

The double quotes there are simply to tell the shell that no word splitting should be performed on the space between bc and d.

If you want your second parameter to contain literal quotes you need to escape them to tell the shell they are literals:

./script1 a '"bc d"'

or

./script1 a \"bc\ d\"

You can use printf to print them in a format that can reused as shell input (escaped):

$ set -- a "bc d"
$ printf '%q\n' "$@"
a
bc\ d

As you can see this only escapes the space though.


As has been explained elsewhere, the double quotes you type are indications to the shell that the enclosed text is to be treated as a single word. If you want to print out the words surrounded by quotes that's fairly straightforward; you just need to include them in the text that you output:

#!/bin/bash
printf '"%s" ' "$@"
printf "\n"

Note that this will add double quotes to every argument, not just those that might have had them when you ran the command.