Home > linux, unix > To bash or not to bash

To bash or not to bash

January 7th, 2009 Leave a comment Go to comments

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 :)

Tags:
  1. January 7th, 2009 at 20:41 | #1

    Hi Laurent,

    I’d glad I’m not the only one who still likes Korn Shell . . .

  2. January 7th, 2009 at 21:59 | #2

    I wonder if you’ve heard this story about ksh:
    http://www.unix.com/whats-your-mind/33991-windows-korn-shell.html

    (BTW. the uncompatible ksh in the story is the same one that prevented me from forking properly)

  3. January 7th, 2009 at 22:34 | #3

    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) : "
    

  4. January 7th, 2009 at 23:57 | #4

    LOL =))
    Very artistic!

  5. January 9th, 2009 at 00:58 | #5

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

  6. January 9th, 2009 at 10:14 | #6

    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)

  7. January 9th, 2009 at 13:27 | #7

    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

  8. January 9th, 2009 at 18:24 | #8

    well done, you got me on that one ;)

    I guess Chen will enjoy that a lot, I am so old-fashion :mrgreen:

  1. No trackbacks yet.
*