public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "Jürgen Wagner" <juergen@wagner.is>
To: cygwin@cygwin.com
Subject: Challenge: a VERY strange problem with command substitution in bash
Date: Tue, 11 Jul 2017 19:12:00 -0000	[thread overview]
Message-ID: <93b0a4e1-78eb-798e-9946-cd38ab288cce@wagner.is> (raw)

[-- Attachment #1: Type: text/plain, Size: 2990 bytes --]

Hello,
  this is my first posting here as I do not see any other hope of
getting this resolved. Research in mailing lists and other Cygwin users'
questions on various sites have not proven to be useful.

1. Ubuntu 4.4.0-71-generic x86_64, /bin/bash

$ value="$( date | cat )"; echo "$? <$value>"
0 <Tue Jul 11 20:21:22 CEST 2017>
$ value="$( date )"; echo "$? <$value>"
0 <Tue Jul 11 20:21:59 CEST 2017>
$ date | cat
Tue Jul 11 20:22:22 CEST 2017

Results are the same for normal users and for root. Everything is fine
and as expected.

2. Windows 10, Version 1703, Build 15063.413 on a Dell 64bit platform,
latest 64bit Cygwin (CYGWIN_NT-10.0, 2.8.1(0.312/5/3) 2017-07-03 14:11
x86_64 Cygwin) /bin/bash

$ value="$( date | cat )"; echo "$? <$value>"
127 <>
$ value="$( date )"; echo "$? <$value>"
0 <Tue Jul 11 20:25:01 CEST 2017>
$ date | cat
Tue Jul 11 20:25:17 CEST 2017

Results are the same for normal users and for users with administrative
rights, even if I run this under the TrustedInstaller rights.
Fully-qualified paths (/bin/date and /bin/cat) does not change the results.

3. On the same Windows 10 system as above, the following forms work fine

$ value="$( date | cat )"; echo "$? <$value>"
0 <Tue Jul 11 20:26:12 CEST 2017>
$ value="$( bash -c 'date | cat' )"; echo "$? <$value>"
0 <Tue Jul 11 20:25:29 CEST 2017>
# value="$( date ; pwd )"; echo "$? <$value>"
0 <Tue Jul 11 20:28:08 CEST 2017
/home/juergen>


Using backquotes instead of the command substitution with $(...) does
not change the results. I could swear this did work in an earlier
version of Cygwin on my Windows 7 machine.

I tried this to see if the code in the parentheses is executed at all:

$ value="$( date 2> foo | cat )"; echo "$? <$value>"

The file "foo" was not created, i.e., it seems the commands don't really
get executed.

$ value="$( date && pwd )"; echo "$? <$value>"
0 <Tue Jul 11 20:49:09 CEST 2017
/home/juergen>

$ value="$( date || pwd )"; echo "$? <$value>"
0 <Tue Jul 11 20:32:27 CEST 2017>

both work, so some control structures seem to be permissible... just not
a pipe.

What is going on? Some misconfiguration? A Cygwin bug? Some interaction
with something weird in Windows 10? I am at loss to understand what
could be wrong... and am now most curious whether anybody has an idea
what is causing this. Does it work/not work in the same way in your
Cygwin installation?

I came across this effect because ssh-host-config did not recognize me
as administrator anymore. It's due to a check for a certain user group
that uses a command substitution with a pipe. Replacing this with an
equivalent command works. The original line used "id -G" and then a
"grep -Eq" to check whether a certain group is on that list.

I am VERY curious now! I've rarely been puzzled that much by such a very
elementary shell expression (looking back at 34 years of Unix experience).

Thanks much in advance!
--Jürgen



[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 3986 bytes --]

             reply	other threads:[~2017-07-11 19:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-11 19:12 Jürgen Wagner [this message]
2017-07-11 19:16 ` Jürgen Wagner
2017-07-11 20:40   ` Jürgen Wagner
2017-07-11 23:22 ` Steven Penny
2017-07-11 23:24 ` Richard Beels via cygwin
     [not found] ` <59655e58.d532240a.ae3d8.4253SMTPIN_ADDED_MISSING@mx.google.com>
2017-07-12  6:08   ` Wouter van Doorn
     [not found] ` <20170711232506.02CE91C3666@atlantis.udag.de>
2017-07-28 18:03   ` Jürgen Wagner
2017-12-04 13:01 Erik Haukjær Andersen
2017-12-04 13:22 ` David Macek
2017-12-04 21:41   ` Brian Inglis
2017-12-04 20:20 ` Andrey Repin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=93b0a4e1-78eb-798e-9946-cd38ab288cce@wagner.is \
    --to=juergen@wagner.is \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).