#!/bin/sh and #!/bin/bash is not the same

Morten Kjærulff mortenkjarulff@gmail.com
Mon Aug 22 23:13:00 GMT 2016


On Mon, Aug 22, 2016 at 8:51 PM, cyg Simple <cygsimple@gmail.com> wrote:
> Please do not TOP POST.
>
> On 8/22/2016 10:36 AM, Morten Kjærulff wrote:
>> Thanks.
>>
>> What I was actually trying, was this:
>>
>> echo a | while read ; do
>>   some_command &
>> done
>> wait
>>
>> The "wait" did not wait. I guessed the reason was that "some_command
>> &" was executed in a subshell.
>>
>> So I tried:
>>
>> while read ; do
>>   some_command &
>> done < <(echo a)
>> wait
>>
>> It was working, however not with #!/bin/sh
>>
>
> What does ``/bin/sh --version'' print?
>
> The wait command is a shell internal command, there is no external
> equivalent. If you /bin/sh is bash then perhaps you've found a bug in
> the emulation of /bin/sh in bash.  Bash takes a different code path when
> named sh.
>
> --
> cyg Simple
>
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>


Sorry, I think I have been confusing.

This:

date
echo a | while read ; do
  sleep 3 &
done
wait
date

will run in 0 seconds, with BOTH /bin/sh and /bin/bash

This:

date
while read ; do
  sleep 3 &
done < <(echo a)
wait
date

will run in 3 seconds with /bin/bash and get syntax errors with /bin/sh:
syntax error near unexpected token `<'
`done < <(echo a)'

$ /bin/sh --version
GNU bash, version 4.3.46(6)-release (x86_64-unknown-cygwin)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

I believe all is ok.

/Morten

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list