bug-bash
[Top][All Lists]
Advanced

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

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


From: Eduardo A . Bustamante López
Subject: Re: Regression -- can't read input w/stderr redirect
Date: Sun, 18 Jun 2017 17:05:39 -0500
User-agent: NeoMutt/20170113 (1.7.2)

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?

I tested on a couple of versions, and the behavior you describe didn't work:

  address@hidden:~/src/gnu/bash-builds$ for b in bash-*/; do $b/bash -c 'echo 
$(< <(echo x)) $BASH_VERSION'; done
  x 3.2.57(1)-release
  x 4.2.0(1)-release
  x 4.2.53(1)-release
  x 4.3.30(1)-release
  
  address@hidden:~/src/gnu/bash-builds$ for b in bash-*/; do $b/bash -c 'echo 
$(< <(echo x) >/dev/stdout) $BASH_VERSION'; done
  3.2.57(1)-release
  4.2.0(1)-release
  4.2.53(1)-release
  4.3.30(1)-release


And if you inspect the source code, you'll notice that this the command
substitution "cat file" functionality is implemented in here:

builtins/evalstring.c:

  413               /* See if this is a candidate for $( <file ). */
  414               if (startup_state == 2 &&
  415                   (subshell_environment & SUBSHELL_COMSUB) &&
  416                   *bash_input.location.string == '\0' &&
  417                   command->type == cm_simple && !command->redirects &&
  418                   (command->flags & CMD_TIME_PIPELINE) == 0 &&
  419                   command->value.Simple->words == 0 &&
  420                   command->value.Simple->redirects &&
  421                   command->value.Simple->redirects->next == 0 &&
  422                   command->value.Simple->redirects->instruction == 
r_input_direction &&
  423                   command->value.Simple->redirects->redirector.dest == 0)
  424                 {
  425                   int r;
  426                   r = cat_file (command->value.Simple->redirects);
  427                   last_result = (r < 0) ? EXECUTION_FAILURE : 
EXECUTION_SUCCESS;
  428                 }

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

- The redirection must be performed inside a command substitution (ln.
  415)
- 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.
  423).

So that means that `echo $(<X 2>Y)' is not a valid "cat file" command
substitution.

I think that you're looking for:

  $ bash -c 'printf "x\0y" > f; { a=$(<f); } 2>/dev/null; declare -p a'
  declare -- a="xy"

Instead.

-- 
Eduardo Bustamante
https://dualbus.me/



reply via email to

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