I'm trying to serialize an array in bash and then export it:
function serialize
{
for i in ${1[@]}; do
ret+=$i" "
done
return ${ret::-1}
}
MEASUREMENT_OUTPUT_FILES=( t1DQ.txt t1CS.txt t2RXe.txt t2e.txt )
export MEASUREMENT_OUTPUT_FILES=${serialize MEASUREMENT_OUTPUT_FILES[@]}
The code produces the following error:
MEASUREMENT_OUTPUT_FILES=${serialize MEASUREMENT_OUTPUT_FILES[@]}: bad substitution
Any ideas what the correct syntax (error in the last line starting with export) would be?
string=${array[*]}.functionkeyword here is a ksh-ism that isn't compatible with POSIX sh; bash supports it for compatibility, but the preferred syntax is the POSIX-compliant one,serialize() {with nofunctionpreceding).