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

Re: Stripping spaces from a shell variable, portably



On Oct 1, 11:27am, DervishD wrote:
}
}     I need to strip leading and trailing spaces from the contents of
} a shell variable, and I need to do it [...] using SuSv3
} constructs, not Zsh extensions.

What about:

	tmp="${variable##*[^ ]}"
	variable="${variable%${tmp}}"
	tmp="${variable%%[^ ]*}"
	variable="${variable#${tmp}}"



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