public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* #!/bin/sh and #!/bin/bash is not the same
@ 2016-08-20 21:32 Morten Kjærulff
  2016-08-20 21:54 ` Hans-Bernhard Bröker
  2016-08-22 13:54 ` cyg Simple
  0 siblings, 2 replies; 7+ messages in thread
From: Morten Kjærulff @ 2016-08-20 21:32 UTC (permalink / raw)
  To: cygwin

Hi,

I thought that #!/bin/sh in a script would be a bash, but it seems not
to be - or what am I doing wrong?

vp01mkf@DX305 ~/bin
$ cat ./tsh.sh
#!/bin/sh

cat < <(pwd)

vp01mkf@DX305 ~/bin
$ ./tsh.sh
./tsh.sh: line 3: syntax error near unexpected token `<'
./tsh.sh: line 3: `cat < <(pwd)'

vp01mkf@DX305 ~/bin
$ cat ./tbash.sh
#!/bin/bash

cat < <(pwd)

vp01mkf@DX305 ~/bin
$ ./tbash.sh
/home/vp01mkf/bin

vp01mkf@DX305 ~/bin
$ diff tsh.sh tbash.sh
1c1
< #!/bin/sh
---
> #!/bin/bash

vp01mkf@DX305 ~/bin
$ ls -l /bin/sh /bin/bash
-rwxr-xr-x 1 vp01mkf Domain Users 757277 Aug  6 14:56 /bin/bash
-rwxr-xr-x 1 vp01mkf Domain Users 757277 Aug  6 14:56 /bin/sh

vp01mkf@DX305 ~/bin
$

/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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: #!/bin/sh and #!/bin/bash is not the same
  2016-08-20 21:32 #!/bin/sh and #!/bin/bash is not the same Morten Kjærulff
@ 2016-08-20 21:54 ` Hans-Bernhard Bröker
  2016-08-22 13:54 ` cyg Simple
  1 sibling, 0 replies; 7+ messages in thread
From: Hans-Bernhard Bröker @ 2016-08-20 21:54 UTC (permalink / raw)
  To: cygwin

Am 20.08.2016 um 19:42 schrieb Morten Kjærulff:
> Hi,
>
> I thought that #!/bin/sh in a script would be a bash, but it seems not
> to be - or what am I doing wrong?

You're asking bash the wrong questions, for starters.  In particular, 
you're mixing up the check whether the shell running that script _is_ 
bash, with whether it _behaves_ like a (full) bash.

To resolve that difference, have a look at

	info bash "Bash Features" "Bash POSIX mode"



--
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: #!/bin/sh and #!/bin/bash is not the same
  2016-08-20 21:32 #!/bin/sh and #!/bin/bash is not the same Morten Kjærulff
  2016-08-20 21:54 ` Hans-Bernhard Bröker
@ 2016-08-22 13:54 ` cyg Simple
  2016-08-22 16:04   ` Morten Kjærulff
  1 sibling, 1 reply; 7+ messages in thread
From: cyg Simple @ 2016-08-22 13:54 UTC (permalink / raw)
  To: cygwin

On 8/20/2016 1:42 PM, Morten Kjærulff wrote:
> Hi,
> 
> I thought that #!/bin/sh in a script would be a bash, but it seems not
> to be - or what am I doing wrong?
> 

If you want to ensure that you have a particular flavor of shell then
don't use /bin/sh.  The reason to use /bin/sh is that POSIX ensures it
exists but it doesn't have to be bash, even on Linux.  For a generic
shell script use ksh syntax, you'll find that it gets you further and is
supported by bash.

-- 
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: #!/bin/sh and #!/bin/bash is not the same
  2016-08-22 13:54 ` cyg Simple
@ 2016-08-22 16:04   ` Morten Kjærulff
  2016-08-22 20:50     ` cyg Simple
  0 siblings, 1 reply; 7+ messages in thread
From: Morten Kjærulff @ 2016-08-22 16:04 UTC (permalink / raw)
  To: cygwin

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

/Morten



On Mon, Aug 22, 2016 at 3:16 PM, cyg Simple <cygsimple@gmail.com> wrote:
> On 8/20/2016 1:42 PM, Morten Kjærulff wrote:
>> Hi,
>>
>> I thought that #!/bin/sh in a script would be a bash, but it seems not
>> to be - or what am I doing wrong?
>>
>
> If you want to ensure that you have a particular flavor of shell then
> don't use /bin/sh.  The reason to use /bin/sh is that POSIX ensures it
> exists but it doesn't have to be bash, even on Linux.  For a generic
> shell script use ksh syntax, you'll find that it gets you further and is
> supported by bash.
>
> --
> 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
>

--
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: #!/bin/sh and #!/bin/bash is not the same
  2016-08-22 16:04   ` Morten Kjærulff
@ 2016-08-22 20:50     ` cyg Simple
  2016-08-22 23:13       ` Morten Kjærulff
  0 siblings, 1 reply; 7+ messages in thread
From: cyg Simple @ 2016-08-22 20:50 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: #!/bin/sh and #!/bin/bash is not the same
  2016-08-22 20:50     ` cyg Simple
@ 2016-08-22 23:13       ` Morten Kjærulff
  2016-08-23 22:19         ` cyg Simple
  0 siblings, 1 reply; 7+ messages in thread
From: Morten Kjærulff @ 2016-08-22 23:13 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: #!/bin/sh and #!/bin/bash is not the same
  2016-08-22 23:13       ` Morten Kjærulff
@ 2016-08-23 22:19         ` cyg Simple
  0 siblings, 0 replies; 7+ messages in thread
From: cyg Simple @ 2016-08-23 22:19 UTC (permalink / raw)
  To: cygwin

On 8/22/2016 3:31 PM, Morten Kjærulff wrote:
> 
> 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)'
> 

See
http://stackoverflow.com/questions/12120598/syntax-error-in-shell-script-with-process-substitution
for the answer to your quandary.

-- 
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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-08-23 17:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-20 21:32 #!/bin/sh and #!/bin/bash is not the same Morten Kjærulff
2016-08-20 21:54 ` Hans-Bernhard Bröker
2016-08-22 13:54 ` cyg Simple
2016-08-22 16:04   ` Morten Kjærulff
2016-08-22 20:50     ` cyg Simple
2016-08-22 23:13       ` Morten Kjærulff
2016-08-23 22:19         ` cyg Simple

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).