bash script bugs

Eric Blake ebb9@byu.net
Thu Dec 3 01:55:00 GMT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Sergey Ivanov on 12/2/2009 6:12 PM:
> Have a script:
> #!/usr/bin/bash
> 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.
> done
> 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:
> /cygdrive/d/install/buf/a.html
> /cygdrive/d/install/buf/b.html
>> while output for ./FileGroupContentsChange.sh
> /cygdrive/d/install/buf/*.html is only
> /cygdrive/d/install/buf/a.html

Well of course.
./FileGroupContentsChange.sh /cygdrive/d/install/buf/*.html
is the same as
./FileGroupContentsChange.sh /cygdrive/d/install/buf/a.html
/cygdrive/d/install/buf/b.html
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 ebb9@byu.net
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/
iEYEARECAAYFAksXGo0ACgkQ84KuGfSFAYDGpgCffC4D/tQbYJsFSjoUkae++HT/
A/MAnRtDC/pYmvcYckDG5KOhK5xeJa6I
=QQA5
-----END PGP SIGNATURE-----
--
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


More information about the Cygwin mailing list

AltStyle によって変換されたページ (->オリジナル) /