On 10/24/21 12:22 PM, Martin Schulte wrote:
Before reading the source I would never have thought that read sets variables
although it returns FAILURE.
Think of them as orthogonal conditions. `read' reads until a newline, or
EOF or other error condition (ignoring timeouts or reading N characte
Hi Greg!
> > Nevertheless, am I right that this solution relies on an undocumented
> > feature?
>
> Which "undocumented" feature did you have in mind? Most things are
> documented, somewhere.
>
> Are you thinking of -d '' signifying NUL as the delimiter? Chet told
> us that he supports this "
On Sun, Oct 24, 2021 at 04:26:44PM +0200, Martin Schulte wrote:
> Hi Greg, hi *!
>
> > For bash scripts using this, I'd go a little bit fancier:
> >
> > read_line() {
> > if (($# == 0)) || [[ ${!#} = -* ]]; then
> > declare -n _rl_lastvar=REPLY
> > else
> > declare -n _rl_lastvar=${!#
Hi Greg, hi *!
> For bash scripts using this, I'd go a little bit fancier:
>
> read_line() {
> if (($# == 0)) || [[ ${!#} = -* ]]; then
> declare -n _rl_lastvar=REPLY
> else
> declare -n _rl_lastvar=${!#}
> fi
> read -r "$@" || test -n "$_rl_lastvar"
> }
Great, thanks - this solu
On Sun, Oct 24, 2021 at 06:41:59PM +0900, Koichi Murase wrote:
> > my apologies if there's a much easier solution for the following
> > problem - in this case please let me know!
>
> We can always define a shell function (which would work in all the
> POSIX shells):
>
> read_line() { read line ||
On Sun, Oct 24, 2021 at 12:42 PM Koichi Murase wrote:
> and I think this is the behavior implied by the POSIX standard:
The spec also says:
> STDIN
> The standard input shall be a text file.
A text file is either empty, or ends with a newline. The behavior of
`read' is undefined when the input i
> my apologies if there's a much easier solution for the following
> problem - in this case please let me know!
We can always define a shell function (which would work in all the
POSIX shells):
read_line() { read line || test -n "$line"; }
printf '%s' "$input" | while read_line; do printf ' %s\n
Hello,
my apologies if there's a much easier solution for the following problem - in
this case please let me know!
>From time to time a run into troubles when reading a file with a while-read
>loop where the last "line" is not terminated with a newline.
I found an ugly looking solution (probab