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 🙂

8 thoughts on “To bash or not to bash

  1. Laurent Schneider Post author

    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. Ludovico Caldara

    Why should I flashback my database in 10g if my restore and recover scripts work very fine since release 8.0??
    🙂

    (the sum of Two+Eight is “Ten” or 10 ???)

  3. Laurent Schneider Post author

    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)

  4. Ludovico Caldara

    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? 😛

Comments are closed.