[Top][All Lists]

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

Re: Regression -- can't read input w/stderr redirect

From: L A Walsh
Subject: Re: Regression -- can't read input w/stderr redirect
Date: Sun, 18 Jun 2017 15:37:31 -0700
User-agent: Thunderbird

Eduardo A. Bustamante López wrote:
On Sun, Jun 18, 2017 at 02:02:05PM -0700, L A Walsh wrote:
 int dpi=$(ord $(<"$pixels_path" 2>/dev/null))
This used to work but now works _unreliably_.

In what version does this used to work?
It used to work when "2>/dev/null" wasn't required to
silence unwanted error messages.

It's clear that the following conditions must be met:

- The redirection must be performed inside a command substitution (ln.
- The command substitution must be a simple command (ln. 417)
- The simple command must consist of a single input redirection (ln.
  420), i.e. no words (ln. 419), no "next" redirection (ln. 421), input
  redirection (ln. 422), and the target being file descriptor 0 (ln.
   Seems unnecessarily limited.  If bash is going to emit out
warnings, then it seems allowing them to be silenced at the point
where they come out would be reasonable, though in this case,
see further on...

I think that you're looking for:

  $ bash -c 'printf "x\0y" > f; { a=$(<f); } 2>/dev/null; declare -p a'
  declare -- a="xy"
Not really -- I hadn't thought about the impact of of NUL's
other than at the end.  For example, if I tried to create a
workaround but tried to read 256, which would have been
encoded as "0x00 0x01 0x00 0x00" -- even in UTF-16:

printf "\0\001\0\0" >/tmp/f ...> a=$(</tmp/f)
bash: warning: command substitution: ignored null byte in input
...> echo "$a"|hexdump -C
00000000  01 0a
 echo $LC_CTYPE

(0x100 = a cap A with a line over it (Ā)).

I'd prefer to see the warning if the NUL byte was other than
at the end. The case with NUL at the end is a standard
string terminator.  I think the warning message wouldn't have been
seen by as many people if it only complained about NUL's in the
middle (vs. as a string-terminator).  No?

reply via email to

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