On 04/21/2015 09:55 AM, Peter Maydell wrote: > If you want pure POSIX shell then it is slightly > uglier as we have to invoke sed: > > argstr="" > for arg in "$@"; do > o=$(printf '%s.\n' "$arg" | sed s/,/,,/g) > argstr=${argstr:+$argstr,}arg=${o%.} > done
It's possible to use IFS= and case to avoid the need to fork, while still writing portable shell, but the solution then takes LOTS more lines of code, so I'm not even going to bother to try writing it here. However, one thing this does NOT handle is an argument that is a literal ','. That is, if I pass 'a', ',' and 'b' as my arguments, this script results in $argstr being a,,,,b, which the qemu parser would read as a single argument of 'a,,b' rather than the three intended arguments. In order to handle that, you'd need some sort of solution that requires an unambiguous separation between arguments. For example, --semihosting-options opt=a,,,,b vs. --semihosting-options opt=a,opt=,,,opt=b would be unambiguous representations of 1 vs. 3 options. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature