Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14292 > unrolled thread

Re: Redirect to variable

Started byIlkka Virta <itvirta@iki.fi>
First post2018-07-03 15:52 +0300
Last post2018-07-03 15:52 +0300
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Redirect to variable Ilkka Virta <itvirta@iki.fi> - 2018-07-03 15:52 +0300

#14292 — Re: Redirect to variable

FromIlkka Virta <itvirta@iki.fi>
Date2018-07-03 15:52 +0300
SubjectRe: Redirect to variable
Message-ID<mailman.3001.1530622411.1292.bug-bash@gnu.org>
On 3.7. 15:43, Robert Durkacz wrote:
> On 5/21/18 Chet Ramey wrote:
>> What you're asking for is syntactic sugar for:
> 
>> some-command > temp-file
>> echo '#' >> temp-file
>> variablename=$(< temp-file)
>> rm -f temp-file
>> variablename=${variablename%?}
> 
>> I would look at a sample implementation, possibly using mmap, if someone
> did one.
> 
> Could someone please explain the reason for inserting and removing the #
> character. It is as if to ensure temp-file is non-empty but it seems to me
> it would work anyway.

Command substitution removes any trailing newlines. Adding an extra 
character to the end prevents that, but then that character itself needs 
to be removed. (Actually, the 'echo' adds a # and an NL, but then the 
command substitution removes the NL so the # remains as last character.)

Run something like  printf "foo bar\n\n" > temp-file  and then try the 
above with and without the #.


-- 
Ilkka Virta / itvirta@iki.fi

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web