-----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 e...@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