bug-bash
[Top][All Lists]
Advanced

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

Re: Redirect to variable


From: Ilkka Virta
Subject: Re: Redirect to variable
Date: Tue, 3 Jul 2018 15:52:59 +0300
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.8.0

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



reply via email to

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