Hi,
I find that I have to make a program quotearg.sh to convert an array
to a string by quoting each element. So that it be used for eval.
I'm not sure if there is a way that I can do eval in bash without
having to use quotearg.sh. If there is no such a way, should
quotearg.sh be added in bash (if it is not available in bash yet), as
it provides a fundamental functionality?
~/linux/bin/src/bash/quotearg/main$ cat ./main.sh
#!/usr/bin/env bash
../quotearg.sh a b c
../quotearg.sh "'" ' ' '"'
../quotearg.sh 'a' 'a b'
echo ================
args=('a' 'a b')
cmd="printf 'x%sx\n' ${args[@]}"
eval "$cmd"
echo ================#the following is what I want, the above is not.
args=('a' 'a b')
arg_string=`../quotearg.sh "${args[@]}"`
cmd="printf 'x%sx\n' $arg_string"
eval "$cmd"
~/linux/bin/src/bash/quotearg/main$ ./main.sh
'a' 'b' 'c'
''\''' ' ' '"'
'a' 'a b'
================
xax
xax
xbx
================
xax
xa bx
--
Regards,
Peng