Mag Gam on 13 Apr 2011 20:21:08 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Bash 101 resources


Thankyou.

Thats why they pay the money for the book :-)


On Tue, Apr 5, 2011 at 3:35 AM, JP Vossen <jp@jpsdomain.org> wrote:
>> Date: Sun, 3 Apr 2011 19:43:30 -0400
>> From: Mag Gam<magawake@gmail.com>
>> Subject: Re: [PLUG] Bash 101 resources
>>
>> Very nice slide show.
>
> Thanks. ÂI hope it's useful.
>
>
>> One comment about the if statements. Should they be double brackets
>> versus single?
>
> It depends...
>
>
>> #correct way?
>> if [[ -d /foo ]]; then
>> Â echo
>> fi
>
> I'd say "new" way.
>
>
>> instead of
>> if [ -d /foo ]; then
>> Â echo
>> fi
>
>
> See my http://www.bashcookbook.com/bashinfo/ page and pick "The bash
> Reference Guide" link for the version of bash you are using. ÂI picked 4.2
> just to have the latest, but this stuff hasn't changed in a while. See the
> "NEWS" and/or "CHANGES" links if you care what changed when.
>
> Anyway...
>
> http://www.bashcookbook.com/bashinfo/source/bash-4.2/doc/bashref.html#SEC83
>
> (Hint: search for 'test' when looking for '[', as there are tons of '['
> characters in the document.)
>
> "Conditional expressions are used by the [[ compound command and the test
> and [ builtin commands. [...]"
>
> So according to Chet, '[[' is a compound command but '[' is a builtin.
>
> What does that mean to you? ÂI dunno.
>
> My *personal* and admittedly imprecise rule-of-thumb is basically this. ÂI
> think of '[[' as the "new" one that can do better pattern matching and
> regular expressions. ÂBut I mostly use the older '[' out of habit unless I'm
> doing something that really needs the new one. ÂAnd come to think of it,
> '[[' is probably less portable. ÂYup. ÂAccording to
> http://princessleia.com/plug/2008-JP_bash_vs_dash.pdf, dash doesn't have
> '[['. ÂIf you don't think you care about dash, you're wrong if you use
> Debian or Ubuntu... ÂSee the link as to why. Â(Hint: /bin/sh == dash in
> newer Ubuntu & Debian, and bash != Bourne != dash...)
>
>
> Getting back to the simple example above, except for portability I don't
> think it really matters if you use '[' or '[['. ÂI'd use '[' out of habit
> and because it's less typing and maybe looks a tiny bit less cluttered.
>
> Actually, for something that simple I'd probably write:
> Â Â Â Â[ -d foo ] && echo 'exists'
>
> Good?
> JP
> ----------------------------|:::======|-------------------------------
> JP Vossen, CISSP Â Â Â Â Â Â|:::======| Â Â Âhttp://bashcookbook.com/
> My Account, My Opinions   |=========|   Âhttp://www.jpsdomain.org/
> ----------------------------|=========|-------------------------------
> "Microsoft Tax" = the additional hardware & yearly fees for the add-on
> software required to protect Windows from its own poorly designed and
> implemented self, while the overhead incidentally flattens Moore's Law.
> ___________________________________________________________________________
> Philadelphia Linux Users Group     --    Âhttp://www.phillylinux.org
> Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
> General Discussion Â-- Â http://lists.phillylinux.org/mailman/listinfo/plug
>
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug