public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* #!/bin/sh vs #!/bin/bash filename expansion after <
@ 2020-08-12 17:54 Morten Kjærulff
  2020-08-12 18:24 ` Eliot Moss
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Morten Kjærulff @ 2020-08-12 17:54 UTC (permalink / raw)
  To: cygwin

Hi,

This script:

#!/bin/sh
echo hello >hello.txt
ls -l
cat hell*
cat < hell*

gives me:

$ ./t.sh
total 2
-rw-r--r-- 1 vp01mkf Domain Users  6 Aug 12 19:51 hello.txt
-rwxr-xr-x 1 vp01mkf Domain Users 60 Aug 12 19:51 t.sh
hello
./t.sh: line 5: hell*: No such file or directory

But if I change line1 to
#!/bin/bash
I get
hello
hello

Is that correct behaviour. I guess so, but why? And what is the rule?

/Morten

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

* Re: #!/bin/sh vs #!/bin/bash filename expansion after <
  2020-08-12 17:54 #!/bin/sh vs #!/bin/bash filename expansion after < Morten Kjærulff
@ 2020-08-12 18:24 ` Eliot Moss
  2020-08-12 20:07 ` Andrey Repin
  2020-08-12 21:07 ` Ken Brown
  2 siblings, 0 replies; 5+ messages in thread
From: Eliot Moss @ 2020-08-12 18:24 UTC (permalink / raw)
  To: Morten Kjærulff, cygwin

On 8/12/2020 1:54 PM, Morten Kjærulff via Cygwin wrote:
> Hi,
> 
> This script:
> 
> #!/bin/sh
> echo hello >hello.txt
> ls -l
> cat hell*
> cat < hell*
> 
> gives me:
> 
> $ ./t.sh
> total 2
> -rw-r--r-- 1 vp01mkf Domain Users  6 Aug 12 19:51 hello.txt
> -rwxr-xr-x 1 vp01mkf Domain Users 60 Aug 12 19:51 t.sh
> hello
> ./t.sh: line 5: hell*: No such file or directory
> 
> But if I change line1 to
> #!/bin/bash
> I get
> hello
> hello
> 
> Is that correct behaviour. I guess so, but why? And what is the rule?

The bash man page describes how its behavior is different when run as sh vs bash :-) ... EM

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

* Re: #!/bin/sh vs #!/bin/bash filename expansion after <
  2020-08-12 17:54 #!/bin/sh vs #!/bin/bash filename expansion after < Morten Kjærulff
  2020-08-12 18:24 ` Eliot Moss
@ 2020-08-12 20:07 ` Andrey Repin
  2020-08-12 20:53   ` Eliot Moss
  2020-08-12 21:07 ` Ken Brown
  2 siblings, 1 reply; 5+ messages in thread
From: Andrey Repin @ 2020-08-12 20:07 UTC (permalink / raw)
  To: Morten Kjærulff, cygwin

Greetings, Morten Kjærulff!

> This script:

> #!/bin/sh
> echo hello >hello.txt
> ls -l
> cat hell*
> cat < hell*

> gives me:

> $ ./t.sh
> total 2
> -rw-r--r-- 1 vp01mkf Domain Users  6 Aug 12 19:51 hello.txt
> -rwxr-xr-x 1 vp01mkf Domain Users 60 Aug 12 19:51 t.sh
> hello
> ./t.sh: line 5: hell*: No such file or directory

> But if I change line1 to
> #!/bin/bash
> I get
> hello
> hello

> Is that correct behaviour. I guess so, but why? And what is the rule?

d2u t.sh
???


-- 
With best regards,
Andrey Repin
Wednesday, August 12, 2020 23:07:08

Sorry for my terrible english...

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

* Re: #!/bin/sh vs #!/bin/bash filename expansion after <
  2020-08-12 20:07 ` Andrey Repin
@ 2020-08-12 20:53   ` Eliot Moss
  0 siblings, 0 replies; 5+ messages in thread
From: Eliot Moss @ 2020-08-12 20:53 UTC (permalink / raw)
  To: cygwin, Andrey Repin, Morten Kjærulff

On 8/12/2020 4:07 PM, Andrey Repin wrote:
> Greetings, Morten Kjærulff!
> 
>> This script:
> 
>> #!/bin/sh
>> echo hello >hello.txt
>> ls -l
>> cat hell*
>> cat < hell*
> 
>> gives me:
> 
>> $ ./t.sh
>> total 2
>> -rw-r--r-- 1 vp01mkf Domain Users  6 Aug 12 19:51 hello.txt
>> -rwxr-xr-x 1 vp01mkf Domain Users 60 Aug 12 19:51 t.sh
>> hello
>> ./t.sh: line 5: hell*: No such file or directory
> 
>> But if I change line1 to
>> #!/bin/bash
>> I get
>> hello
>> hello
> 
>> Is that correct behaviour. I guess so, but why? And what is the rule?
> 
> d2u t.sh
> ???

Yes, you need to watch line endings under cygwin!  The usual Windows CR-LF
can cause a world of grief.  You can mount drives to hide this, but doing
so can mess up reading binary files ...

EM

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

* Re: #!/bin/sh vs #!/bin/bash filename expansion after <
  2020-08-12 17:54 #!/bin/sh vs #!/bin/bash filename expansion after < Morten Kjærulff
  2020-08-12 18:24 ` Eliot Moss
  2020-08-12 20:07 ` Andrey Repin
@ 2020-08-12 21:07 ` Ken Brown
  2 siblings, 0 replies; 5+ messages in thread
From: Ken Brown @ 2020-08-12 21:07 UTC (permalink / raw)
  To: cygwin

On 8/12/2020 1:54 PM, Morten Kjærulff via Cygwin wrote:
> Hi,
> 
> This script:
> 
> #!/bin/sh
> echo hello >hello.txt
> ls -l
> cat hell*
> cat < hell*
> 
> gives me:
> 
> $ ./t.sh
> total 2
> -rw-r--r-- 1 vp01mkf Domain Users  6 Aug 12 19:51 hello.txt
> -rwxr-xr-x 1 vp01mkf Domain Users 60 Aug 12 19:51 t.sh
> hello
> ./t.sh: line 5: hell*: No such file or directory
> 
> But if I change line1 to
> #!/bin/bash
> I get
> hello
> hello
> 
> Is that correct behaviour. I guess so, but why? And what is the rule?

 From https://tiswww.case.edu/php/chet/bash/POSIX:

When invoked as 'sh', Bash enters POSIX mode after reading the startup
files.

The following list is what's changed when 'POSIX mode' is in effect:

   1. Bash ensures that the 'POSIXLY_CORRECT' variable is set.

[...]

   11. Redirection operators do not perform filename expansion on the
      word in the redirection unless the shell is interactive.

[...]


Ken

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

end of thread, other threads:[~2020-08-12 21:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-12 17:54 #!/bin/sh vs #!/bin/bash filename expansion after < Morten Kjærulff
2020-08-12 18:24 ` Eliot Moss
2020-08-12 20:07 ` Andrey Repin
2020-08-12 20:53   ` Eliot Moss
2020-08-12 21:07 ` Ken Brown

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