News for hackers. Stuff that matters.
Re:Bash Pitfalls by pdkl95 on Sunday August 16, 2015 @08:05PM (#10070766)
Bash isn't particularly hard. Unfortunately, it carries a significant amount of historical baggage that make things very confusing. Many examples and existing bash scripts usew these older feature which can make learning bash even more confusing.

A couple examples of what I mean are:

    # old style command substitution (don't use this)
    echo "`ls *.mp3 | wc -l` MP3 files in $PWD"
    # new style
    echo "$(ls *.mp3 | wc -l) MP3 files in $PWD"

    # while it is used in some place, the use of $*
    # to mean "all arguments" is probably always wrong
    for i in $* ; do do_something $i ; done
    # instead, you almost always want "$@"
    # (and always use quotes on variable expansion)
    for i in "$@" ; do do_something "${i}" ; done
A lot of really nasty sometimes-incorrect behavior goes away when you use the modern replacements.

Another big thing that confuses people at first with sh/bash style shell script is that they treat it like a regular programming language. Instead, realize that most of the magic happens as "expansions" of the command line. Thinking about bash a something closer to a fancy macro language doing simple string manipulates can help a lot.

Finally: RTFM. Seriously. Modern versions of bash have a very nice manual. Cargo-culting pieces of existing scripts may solve an immediate problem, but it won't teach you the real language nearly as well as simply reading bash(1) (especially the "EXPANSIONS" section).

Re:Bash Pitfalls by angersock on Sunday August 16, 2015 @08:50PM (#10070892)
Is there a good online resource (other than man pages) for those of us who are exceptionally lazy to learn modern Bash?
Re:Bash Pitfalls by pen2l on Sunday August 16, 2015 @08:53PM (#10070901)
greycat's writing are the best thing for bash, in my opinion. The submitted article is his 'bash pitfalls'... his formal bash guide is here: http://mywiki.wooledge.org/BashGuide

greycat is a guy who idles in #bash on freenode and has helped thousands of people.

Re:Bash Pitfalls by angersock on Sunday August 16, 2015 @08:55PM (#10070906)
Thanks!