In the below code, I would like to have the output of pyfg()
passed exactly as echoed (i.e. with the space between -htns
and crl
being interpreted literally, not as whitespace, by aoeu()
) to aoeu()
. Of course, the problem is that in aoeu()
, $1
is -htns
, $2
is crl
, and $3
, which I don't want at all in this case, is qjkx
. I know this example is thoroughly useless, but the real application to which I'm trying to apply this calls an external program in place of the below aoeu()
, so I do need something like what's below.
#!/bin/bash
# pass_space_function.sh
aoeu() {
echo "$1" "$2"
}
pyfg() {
echo "-htns crl" "qjkx"
}
aoeu $(pyfg)
My running the above outputs:
$ ./pass_space_function.sh
-htns crl
My desired output is:
$ ./pass_space_function.sh
-htns crl qjkx
To be clear, I do understand exactly why my code isn't working, but that about which I'm not so sure is how to make it do what I want it to do.
EDIT:
#!/bin/bash
aoeu() {
echo 1:"$1" 2:"$2" 3:"$3"
}
pyfg() {
# These variables might be user-provided.
wvz="/usr/lib/scarychacacters_\"@#$:%^&:*(){}[]; a o ;u ;::e i y f.so.4"
bm="/space space space"
snt="/var/cache/normalpath"
printf "%q %q %q" "$wvz" "$bm" "$snt"
}
aoeu $(pyfg)
That code returns, for me, 1:/usr/lib/scarychacacters_\"@#\$:%\^\&:\*\(\)\{\}\[\]\;\ 2:a\ 3:o\
. It's obviously splitting at the whitespace in $wvz
.