Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Printing arrays for use with $()



On Aug 11,  7:01pm, DervishD wrote:
}
}     Hi Bart :)

"Hi, Raúl!"

}     Impossible for most commands.

Hence the short answer ...

}     So, if I must pass a list of filenames from one app to another in
} the most generic way, which are my options?

It all comes back to having some degree of control over the calling
environment.  For example, if it were sufficient that

	du -s *.whatever
and
	eval du -s `myscript`

were equivalent, then

	print -r -- ${(q)array}

should be enough.

On Aug 12, 12:28am, DervishD wrote:
} Subject: Re: Printing arrays for use with $()
}
}     I've been trying this (without success):
} 
}     command $(printf '"%s "' $array) 

Even if that would work (which, as you've seen, it does not) why would
you want to include a trailing space *inside* the double quotes?

}     The worst thing is that I had the intention of using a couple
} more scripts in this way, generating a list of files to work on and
} dumping it to stdout :( but without being able to solve this
} problem...

Well, you could always change tack entirely and instead of

	du -s `myscript`

you could call

	myscript du -s

That is, have your script work the way zargs does.  Or you could modify
zargs to use ${(z)...} on its list of files, and then run

	qzargs -- `myscript` -- du -s

But again all of this assumes you can control the caller, which means
you could just as easily require IFS=$'\0'.  There's just no way around
this, given the semantics of $(...) and word splitting.



Messages sorted by: Reverse Date, Date, Thread, Author