[plug] Things I never knew about BASH

Ryan ryan at is.as.geeky.as
Wed Jul 30 08:48:05 WST 2003


Greetings,

Last week I was tinkering with an f-prot virus definition update script
and saw some strange things I'd never seen before.  After some searching
I found them in the elongated bash man page under "Parameter Expansion"

This probably exists in other shells too, but I was deprived as a linux
newbie and never ventured much beyond bash.

<shell propaganda>

All this time I was using sed, awk, grep, cut  etc.  why not use these
where they bit the bill?

       ${parameter:-word}

       ${parameter:=word}

       ${parameter:?word}

       ${parameter:+word}

       ${parameter:offset}
       ${parameter:offset:length}
 
       ${#parameter}
 
       ${parameter#word}
       ${parameter##word}
 
       ${parameter%word}
       ${parameter%%word}
                                                                     
       ${parameter/pattern/string}
       ${parameter//pattern/string}

Do have a look.

</shell propaganda>

Simple things still entertain me :)

Ryan



More information about the plug mailing list