I would like to print out augments of a function to a file.
I was told a command printf "%q "
, whose instruction is following,
# man printf
%q ARGUMENT is printed in a format that can be reused as shell input, escaping non-print‐
able characters with the proposed POSIX $'' syntax.
On the basis of instruction above, I tried following code.
#!/bin/bash
# file name : print_out_function_augs.sh
output_file='output.txt'
function print_augs() {
printf "%q " "$@" >> "${output_file}"
echo >> "${output_file}"
}
print_augs a 'b c'
cat "${output_file}"
rm "${output_file}"
and run
bash print_out_function_augs.sh
The results are following,
a b\ c
I expected the results as
a 'b c'
which is the original augments to print_augs function.
Why does the output and the original augments are different? Or can I print out the original augments as they are?
Thank you very much.