help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mapfile question: Is there a better way to avoid the trailing newline?


From: Stan Marsh
Subject: mapfile question: Is there a better way to avoid the trailing newline?
Date: Wed, 01 Oct 2025 12:49:20 -0600

--- Cut Here ---
$ foo=$'this is a\ttest of this\tthat one'
$ declare -p foo
declare -- foo=$'this is a\ttest of this\tthat one'
$ mapfile -t -d $'\t' <<< "$foo"; declare -p MAPFILE
declare -a MAPFILE=([0]="this is a" [1]="test of this" [2]=$'that one\n')
$
--- Cut Here ---

Note the trailing newline on the last element of MAPFILE.  Now, this
is easily handled by either of:

    echo "${MAPFILE[2]%?}"
or
    echo "${MAPFILE[2]/$'\n'}"

But is there a way to avoid the problem in the first place? (while
still using mapfile, though I am open to other suggestions)

=================================================================================
Please do not send me replies to my posts on the list.
I always read the replies via the web archive, so CC'ing to me is unnecessary.

When responding to my posts, please try to refrain from giving bureaucratic 
answers.
If you have nothing useful to say, then just click Next and go on.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]