
Bash Shell Scripting in 10 seconds - bennick
http://www.aboutlinux.info/2005/10/10-seconds-guide-to-bash-shell.html
======
nescafe
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.

~~~
AlexandrB
Do you know of a better intro? I wasn't even aware of [[ ]] :(

~~~
nescafe
<http://mywiki.wooledge.org/EnglishFrontPage>

------
RyanMcGreal
Took longer than 10 seconds, but a helpful introduction nonetheless.

------
babarock
Small nitpick:

for file in _.java; do javac $file; done

This will break if the filename contains funky characters like newline or
whitespaces. You should prefer using find instead:

find . -name '_.java' -exec javac {} \\+

Also, I would suggest adding a pragaraph about proper quoting, I usually find
it to be an issue beginners struggle with the most.

~~~
nescafe
Find is overkill for this.

    
    
      for file in *.java; do
         [[ -f $file ]] || continue
         javac "$file"
      done

~~~
babarock
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.

~~~
jcromartie
It will compile files with whitespaces. That's what [[]] is for.

~~~
babarock
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.

~~~
jcromartie
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".

------
kmm
Thank you! I've been looking for a condensed yet thorough overview of bash for
quite some time. I use bash only sporadically and I am never successful when
googling easy things like how to test for equality of numbers.

------
xbryanx
I wish I'd found this a long time ago. It took me forever to discover the
totally un-googlable but super useful bash variable $?

Dumb, I know, but sometimes the obvious beginner stuff is easy to overlook.

------
ez77
Quoting typo:

    
    
      echo $IFS | od -bc
    

only makes sense as

    
    
      echo "$IFS" | od -bc

------
johncoltrane
10?

~~~
drostie
I suppose that if one were a Bash God, as being any other sort of God, "one
day is as a thousand years, and one thousand years is as a day." This implies
that you routinely underestimate time by a factor of 365 250. That number of
seconds would be about 4.2 days, so to a Bash God, 10 seconds is as 42 days.

42 days is I guess a reasonable estimate for learning Bash if you're really
new and coming from Windows -- but perhaps it's a little too much; you could
probably get fluent in two weeks if you really focused and already knew the
basics of programming.

So the Bash Gods should clearly revise the number down to three seconds.

