News for hackers. Stuff that matters.
Re:Bash Shell Scripting in 10 seconds by nescafe on Monday February 27, 2012 @09:08AM (#3638981)
Find is overkill for this.

  for file in *.java; do
     [[ -f $file ]] || continue
     javac "$file"
  done
Re:Bash Shell Scripting in 10 seconds by babarock on Monday February 27, 2012 @09:32AM (#3639062)
This would avoid errors on the files with whitespaces, however it will also avoid compiling them. You cannot make the assumption that a file with a whitespace should not be compiled.
Re:Bash Shell Scripting in 10 seconds by nescafe on Monday February 27, 2012 @11:05AM (#3639404)
Incorrect. Word splitting does not happen in [[ ]] tests. The only reason I had the [[ -f $file ]] || continue is to handle the case where there are no .java files, which will cause the for loop to iterate once with file set to '*.java'. i could have also used nullglob,but chose not to.
Re:Bash Shell Scripting in 10 seconds by jcromartie on Monday February 27, 2012 @09:41AM (#3639090)
It will compile files with whitespaces. That's what [[]] is for.
Re:Bash Shell Scripting in 10 seconds by babarock on Monday February 27, 2012 @09:53AM (#3639128)
No it won't, [[ -f $file ]] will fail and `continue` will be executed, moving on to the next iteration of the loop. Think of the different successive values the $file variable will have. At no point, will it hold the full name of the file at once.
Re:Bash Shell Scripting in 10 seconds by jcromartie on Monday February 27, 2012 @12:32PM (#3639727)
I think you're confused. I just tried this in a few shells.

It works in Bash on Cygwin and OS X.

    touch "file with spaces"
    for f in *; do if [[ -f $f ]]; then echo file: $f; fi; done;
This echoes one line for "file with spaces".
Re:Bash Shell Scripting in 10 seconds by pyre on Monday February 27, 2012 @11:33AM (#3639494)
I realize that this is specifically for bash, but this won't work in zsh:

  % for blah in *.java; do echo $blah; done
  zsh: no matches found: *.java
Re:Bash Shell Scripting in 10 seconds by cmurphycode on Monday February 27, 2012 @11:38AM (#3639520)
That's just the zsh regex quirk; try quoting *.java.
Re:Bash Shell Scripting in 10 seconds by SageRaven on Monday February 27, 2012 @11:20AM (#3639447)
What if "*.java" expands to something too large? Or is that only a relevant concern on the command line itself ("Argument list too long" error) and not within a script?
Re:Bash Shell Scripting in 10 seconds by waitwhat on Monday February 27, 2012 @09:14AM (#3639009)
you need to doublequote $file on your second line:

      [[ -f "$file" ]] || continue