I'm reducing the question to (I believe) the simplest case. Let's say I have a script
myscript.sh with the following contents:
#!/bin/bash IFS='%20' echo "$*"
If I run the command as follows, the output will look like:
me@myhost ~ $ ./myscript.sh fee fi fo fum fee%fi%fo%fum
This is expected behavior, as described in the
bash man page:
* Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a sin- gle word with the value of each parameter separated by the first character of the IFS special variable. That is, "$*" is equiva- lent to "$1c$2c...", where c is the first character of the value of the IFS variable. If IFS is unset, the parameters are sepa- rated by spaces. If IFS is null, the parameters are joined without intervening separators.
However, what I would like to get is the output:
Thus using a multiple character separator field rather than a single character.
Is there a way to do this that is native to
Based on the data from mikeserv below, and the writeup at Why is printf better than echo?, I ended up doing the following (again reduced to simplest case as in the example above):
#!/bin/bash word="$1" shift if [ "$#" -gt 0 ] ; then word="$word$(printf '%%20%s' "$@")" fi printf '%s\n' "$word" unset word