Menu

command substitution does not work on bash

2016-02-20
2016-03-08
  • Shusaku KIMURA

    Shusaku KIMURA - 2016-02-20

    Hi,

    It seems that the command substitution does not work on sh (=bash). I wrote the following shell script and save as t.sh.

    #!/bin/sh
    A=`echo FOO | grep FOO`
    echo x$A
    

    When executed it, the following result was got. But correct result is 'xFOO'.

    $ chmod +x t.sh
    $ ./t.sh
    x
    

    I confirmed the issue on Windows 10 64bit and Windows 8.1 64bit. To install MSYS2, 64bit installer was used.

    I'm sorry if this is known issue, but I could not find the topics about it. Please tell me any work arrounds.

    Regards,
    Shusaku KIMURA.

     

    Last edit: Shusaku KIMURA 2016-02-20
  • David Macek

    David Macek - 2016-02-20

    I'm not able to confirm on msys64 on Windows 10.

    Does bash t.sh also not work for you? If yes, can you paste the output of bash -xv a.sh?

     
    • Shusaku KIMURA

      Shusaku KIMURA - 2016-02-21

      Thank you for the reply.

      Does bash t.sh also not work for you? If yes, can you paste the output of bash -xv a.sh?

      Yes. Same result was got.

      $ bash -xv t.sh
      #!/bin/sh
      A=`echo FOO | grep FOO`
      echo FOO | grep FOO
      + A=
      echo x$A
      + echo x
      x
      $
      

      Using zsh, correct result were got.

      $ zsh -xv ./t.sh
      #!/bin/sh
      A=`echo FOO | grep FOO`
      +./t.sh:2> A=+./t.sh:2> echo FOO
      +./t.sh:2> A=+./t.sh:2> grep FOO
      +./t.sh:2> A=FOO
      echo x$A
      +./t.sh:3> echo xFOO
      xFOO
      

      I checked the problem on three different PCs (Win10, Win8.1 and Win8.1 (all 64bit)), and same results were got. Does this problem occur only for me? If so, it is assent that no questions about it cannot be found on the web.

      Although it may not be public benefit, If you have any idea to investigate the cause of the problem, could you please tell me? Because of this problem, some configure scripts does not work.

      Regards,
      Shusaku KIMURA.

       
      • Shusaku KIMURA

        Shusaku KIMURA - 2016-02-21

        I checked t.sh on Windows8.1 32bit and MSYS2 32bit, and correct result could be got.

        And I tried re-installing MSYS2 64bit on Windows10 64bit using msys2-x86_64-20150916.exe, and correct result could be got. But, after executing update-core, the problem began to occur.

        Regards,
        Shusaku KIMURA.

         
  • David Macek

    David Macek - 2016-02-22

    I'm running the latest 64-bit MSYS2 and have tested this on Windows Server 2012 R2 and Windows 10.

    $ pacman -Ss msys2-runtime
    msys/msys2-runtime 2.4.1.16860.40c26fc-1 (base) [installed]
    

    It looks like your bash (or sh) has problems forking.

    1. Try restarting.
    2. Did you follow the upgrade process?
    3. Check if you're running anything from BLODA.
    4. Capture the output of strace bash -xv t.sh and paste it somewhere (probably not directly into this discussion, but rather onto pastebin or similar).

    Seems related to http://sourceforge.net/p/msys2/tickets/245/.

     
    • Shusaku KIMURA

      Shusaku KIMURA - 2016-02-23

      Thank you very much for kindly reply.

      I found MacType causes the problem. After uninstalling MacType, t.sh began to work correctly. MacType is listed in BLODA.

      I did not know BLODA and I had not searched the topics about this problem in association with Cygwin, although I should know MSYS2 is derived from Cygwin. I agree ticket #254 seems to be similar problem, but I could not find it too. I am ashamed of myself.

      I tried to execute strace for reference, but SEGV occured and nothing to be got. After uninstalling MacType, strace also works well.

      Thanks again.

      Regards,
      Shusaku KIMURA.

       
  • David Macek

    David Macek - 2016-03-08

    I'm glad to hear the issue got resolved.

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.