dce@Solbourne.COM (David Elliott) (04/21/89)
In article <8283@ihlpf.ATT.COM> lukas@ihlpf.UUCP (Lukas,J.) writes: >Can anyone explain why this syntax: > > for file; do > >works fine with ksh, but fails with sh with a message like: > > unexpected ; The likely answer is that sh just wasn't written to handle this case. Either the ksh parser works differently, or someone working with ksh decided that this was a bug and fixed it. I think you'll find that for file do works just fine. >The syntax: > > for file in $@; do > >works fine with both ksh and sh. TIA The term "works fine" is a relative term (high horse time again). If you use $@ and not "$@", it's kind of like wearing a condom made of cheesecloth. -- David Elliott dce@Solbourne.COM ...!{boulder,nbires,sun}!stan!dce
lukas@ihlpf.ATT.COM (00771g-Lukas) (04/24/89)
Thanks to Chris Torek, Greg Ubben, and Dave Elliott for their replies. The answer seems to be that that is just the way that it is. In the case of the Bourne shell anyway, ";" does not always equal a <newline>. BTW. As Greg pointed out: > Also, someone pointed out that there is a very trivial bug with "$@" in > Bourne shell only, in that if there are no arguments, "$@" will actually > expand to one null arguement. Use ${@:+"$@"} to fix this. -- John Lukas att!ihlpf!lukas 312-510-6290
guy@auspex.auspex.com (Guy Harris) (04/26/89)
>> Also, someone pointed out that there is a very trivial bug with "$@" in >> Bourne shell only, in that if there are no arguments, "$@" will actually >> expand to one null arguement. Use ${@:+"$@"} to fix this. Well, some versions of the Bourne shell, anyway. The S5R3 version has this fixed, so any system whose Bourne shell is based on that version won't have the problem. However, for now, you may still want to program defensively....