Concatenate all arguments and wrap them with double quotes
@msw has the right idea (up in the comments on the question). However, another idea to print arguments with quotes: use the implicit iteration of printf
:
foo() { printf '"%s" ' "$@"; echo ""; }foo bla "hello ppl"# => "bla" "hello ppl"
Use parameter substitution to add " as prefix and suffix:
function foo() { A=("${@/#/\"}") A=("${A[@]/%/\"}") echo -e "${A[@]}"}foo bla "hello ppl" kkk 'ss ss'
Output
"bla" "hello ppl" "kkk" "ss ss"
You can use "$@" to treat each parameter as, well, a separate parameter, and then loop over each parameter:
function foo() {for i in "$@"do echo -n \"$i\"" "doneecho}foo bla "hello ppl"