This is the mail archive of the
mailing list for the Cygwin project.
Re: bash script bugs
-----BEGIN PGP SIGNED MESSAGE-----
According to Sergey Ivanov on 12/2/2009 6:12 PM:
> Have a script:
> f="$(ls $1)"
The quotes around $(), while nice for consistency, are not strictly
necessary (since $() forms a word without quoting, and variable assignment
is not subject to word splitting). Meanwhile, you are missing quotes
around $1. And did you really mean $1, or did you want $@?
> for v_file in "$f"; do
Why are you quoting $f? That means that v_file will be exactly equal to
one item during the loop: $f, regardless of whether an unquoted $f would
have split into multiple words.
> echo $v_file
But now, by not quoting $v_file, you run afoul of any IFS issues, such as
a file name containing multiple spaces.
> named FileGroupContentsChange.sh.
> Twos things do not work as they should. By order:
> 1) Output in command line for nest commands
> ls /cygdrive/d/install/buf/*.html
> dir /cygdrive/d/install/buf/*.html
> is same:
> while output for ./FileGroupContentsChange.sh
> /cygdrive/d/install/buf/*.html is only
Well of course.
is the same as
since the shell expands * PRIOR to calling the script. Thus, when the
script starts, $1 is /cygdrive/d/install/buf/a.html and $2 is
/cygdrive/d/install/buf/b.html, but your script didn't use $2.
And none of this is cygwin-specific.
> 2) (not critical but not "classical") Both command line script and
> outputs for current folder in one line:
> ls returns
> FileGroupContentsChange.sh cygcheck.out sources
> and so ./FileGroupContentsChange.sh do
Of course. Calling ./FileGroupContentsChange.sh without arguments unsets
$1; then since you used $1 without quotes, you ended up calling ls without
arguments, and ls without arguments lists the contents of the current
directory. Again, none of this is cygwin-specific, nor does it represent
a bug in anything except your expectations of your script.
Don't work too hard, make some time for fun as well!
Eric Blake firstname.lastname@example.org
volunteer cygwin bash maintainer
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
-----END PGP SIGNATURE-----
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple