Boston Linux & UNIX was originally founded in 1994 as part of The Boston Computer Society. We meet on the third Wednesday of each month at the Massachusetts Institute of Technology, in Building E51.

BLU Discuss list archive

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

[Discuss] What the use of .bashrc

In the bash manpage, the "case" command is documented in the usual
opaque ;-) way:

       case word in [ [(] pattern [ | pattern ] ... ) list ;; ] ... esac
              A  case  command first expands word, and tries to match
it against each pattern in turn, using the
              same matching rules as for pathname  expansion  (see
Pathname  Expansion  below).....

Close reading of the manpage will reveal how the expansion and pattern
matching work.
(NB:  the "star" (*) characters in the pattern are NOT quoted.)

BTW, the "case" command is inherited from the original Bourne shell.
Bash also supports regular expression matching with the =~ operator;
you could rewrite the pattern-matching part of pathmunge as:

if [[ ! ":$PATH;' =~ ":$1:" ]] ; then
  # append or prepend, as above

but (IIRC) that code would NOT work with a POSIX shell.

- Steve

> Date: Tue, 30 Oct 2012 11:46:41 -0400
> From: John Abreau <abreauj at>
> To: Jerry Feldman <gaf at>
> Cc: discuss at
> Subject: Re: [Discuss] What the use of .bashrc
> Message-ID:
>         <CAFv2jcatMnWTJFC7JioF2_EPH+LVovNrmF31VfLTHXtSHcwHYg at>
> Content-Type: text/plain; charset=ISO-8859-1
> I just looked for that in the bash manpage, and i can't find anything
> describing
> that behavior. Can you highlight where you discovered that?
> On Tue, Oct 30, 2012 at 11:07 AM, Jerry Feldman <gaf at> wrote:
>> On 10/30/2012 10:58 AM, joe at wrote:
>>>   Looks to me like the first test only tests if $1 is not at the end of $PATHor am I missing something?    ----- Original Message -----From: &quot;Jerry Feldman&quot; >;gaf at
>> No, it tests is $1 exists in $PATH.
>> I really hate bash pattern matching because I have to read the manual
>> every time I use them.
>> in this case '*:"$1":*' looks for $1 anywhere in $PATH.
>> --
>> Jerry Feldman <gaf at>
>> Boston Linux and Unix
>> PGP key id:3BC1EB90
>> PGP Key fingerprint: 49E2 C52A FC5A A31F 8D66  C0AF 7CEA 30FC 3BC1 EB90
>> _______________________________________________
>> Discuss mailing list
>> Discuss at
> --
> John Abreau / Executive Director, Boston Linux & Unix
> PGP KeyID: 32A492D8 / Email: abreauj at
> PGP FP: 7834 AEC2 EFA3 565C A4B6  9BA4 0ACB AD85 32A4 92D8

BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!

Boston Linux & Unix /