2009-03-26, 21:22(-04), Chet Ramey:
> Chris F.A. Johnson wrote:
>
>>    Chet, how about an option to mapfile that strips leading and/or
>>    trailing spaces?
>> 
>>    Another useful option would be to remove newlines.
>
> I'm disinclined to add one, since it's easy enough to use the
> ${line##[     ]} and ${line%%[        ]} constructs to remove
> leading and trailing whitespace.  You can use the same expansions
> or pattern substitution to remove newlines (using $'\n' to denote
> a newline).
[...]

That removes only one blank, to strip all blanks, you'd need to
enable ksh extended globbing (shopt -s extglob) and do

${line##+([[:blank:]])}

Or POSIXly:

${line#"${line%%[![:blank:]]*}"}

Not extremely legible.

Note that "read" does strip leading and trailing blanks (as long
as those blank characters are in IFS and as long as a variable
name is provided to it), so it's not completely unreasonable to
ask that "readarray" (aka mapfile) has an option to do that as
well.

-- 
Stéphane

Reply via email to