To bash or not to bash

I have been inspired by Chen to talk about bash…

I have been using ksh for many years, and I mean ksh88 not ksh93. The main reason is, I want my script to run the same way in any Unix flavor.

ksh93 has never been too much popular. I used it a few time to sleep half a second


echo sleep 0.5| /usr/dt/bin/dtksh

ksh has a lot of nice features. I just used one of them in my script :


$ typeset -u name
$ read name?"Enter your name : "
Enter your name : Laurent
$ echo $name
LAURENT

Way easier to force a variable to be uppercase rather than using echo|tr etc

Bash has some nice features too, but unfortunately every OS release come with a different bash version, which is the same pain as perl when you want to write a script that last for a decade or two.

Ok, just4fun


$ mkdir -p {a..z}/{1..9}
... create directories a/1 a/2 ... z/8 z /9
$ [[ text =~ t..t ]] 
... check if text matches regular expression t..t
$ echo ${text/pattern/string}
... replace pattern by string

The first two commands require bash3, the last is just fine with bash2.

Have fun shell-scripting :)

Published by

Laurent Schneider

Oracle Certified Master

8 thoughts on “To bash or not to bash”

  1. ksh is way more artistic than bash. For example, in bash, if you want the time in your prompt, you do something like PS1=’\t ‘

    In ksh, I found this a few years ago, enjoy…

    
    export SECONDS="$(date '+3600*%H+60*%M+%S')"
    hh="(SECONDS/3600)%24"
    mm="(SECONDS/60)%60"
    ss="(SECONDS%60)"
    time='${_x[ (_m=mm)==(_h=hh)==(_s=ss) ]}$_h:$_m:$_s'
    PS1="($time) : "
    

  2. not sure how it is related to bash but the key answer is time to recover!

    Since 8.0 your db has grown a lot, did you also update your tape libraries to maintain a reasonable time to recover? Maybe your HA requirements just changed in such a way a downtime of 1 hour got unacceptable, well, probably you do not need flashback database :) (it is 10)

  3. I was joking about features that comes with latest releases and scripts that last for a decade ;-)
    Actually I write my scripts with latest features of bash,gawk, and perl (the perl shipped within oracle) for a certain platform because I guess future installations will do have at least these ones! I rearrange/rewrite indeed the scripts for various unix flavours.
    Could I live without JMX just because java 1.4 doesn’t have it? :-P

Leave a Reply

Your email address will not be published.


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>