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
--
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to