nescafe
Re:Bash Shell Scripting in 10 seconds
on Monday February 27, 2012 @11:06AM (#3639410)
Re:Bash Shell Scripting in 10 seconds
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
on Monday February 27, 2012 @09:18AM (#3639020)
Linked article is actually a really horrible intro to bash -- at best, it is an OK intro to pre-POSIX bourne shell scripting.
Specifically:
* test and [ ] are fraught with parameter expansion peril. Use [[ ]] instead.
* The author uses single quotes around strings that are demonstrating parameter expansion. Single quotes inhibit parameter expansion, so every one of those examples is wrong.
* select is a better tool than read; case for most of his case-relasted demos.
* Backticks ( ` ` ) are the devil.
At least he points people greg's wiki at the end.
Re:Bash Shell Scripting in 10 seconds
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:Writing Robust Bash Shell Scripts
on Saturday January 14, 2012 @09:23PM (#3466093)
No, that is just wrong. In double-brackets, bash will handle expansion and testing of unset variables and variables with spaces just fine, because word splitting and pathname expansion are not performed in double braces -- they are shell syntax, as opposed to single brackets, which are commands. Your syntax error happened because you don't have a fi matching that if.
As a counterexample:
(echo $BASH_VERSION;
foo=foo; [[ $foo = foo ]] && echo $foo;
foo="1 2 3"; [[ $foo = "1 2 3" ]] && echo $foo;
foo=''; echo ${foo?"No foo for you"};
unset foo; echo ${foo?"No foo for you"})
4.2.10(1)-release
foo
1 2 3
bash: foo: No foo for you
That last one is one of the few ways you can tell whether a variable is unset or merely set to an empty string.lrn2bash.