<div class="gmail_quote">On Thu, Nov 18, 2010 at 9:48 AM, Colin Law <span dir="ltr"><<a href="mailto:clanlaw@googlemail.com">clanlaw@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I have a problem with filename expansion in a script and am having<br>
difficulty understanding what is going on.<br>
In a terminal, if I enter<br>
ls {a*,b*}<br>
I see all files beginning with a or b (I know this is not the best way<br>
of doing that but it is a simple example of the problem I am seeing).<br>
If I put that line in a file test.sh, make it executable, and then type<br>
./test.sh<br>
then I see the same result. However if at the start of test.sh I put the line<br>
#!/usr/bin/env sh<br>
at the start of test.sh and then run it I get<br>
ls: cannot access {f*,l*}: No such file or directory<br>
<br>
It seems that brace expansion is not being performed in this case. If<br>
I just use wildcards it is ok, it is the braces that cause the<br>
problem. In order to determine whether a different shell was running<br>
for some reason I also put<br>
finger -l<br>
in the script, and in both cases, with and without the shebang line,<br>
it showed /bin/bash as the shell.<br>
<br>
If, however, I put<br>
#!/bin/bash<br>
at the start then it works, still showing /bin/bash as the shell.<br>
<br>
Can someone explain what is going on?<br></blockquote></div><br>Yes, your default shell is probably /bin/bash, which is why your console entry works. By specifying the use of 'sh' you get a shell from /bin/dash (note bash vs dash). If you specify "#!/usr/bin/env bash" instead, your script will work much like your console.<br>
<br>...Ken<br><br>