Bash Script equivalent KSH script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash Script equivalent KSH script?
# 1  
Old 03-08-2010
Bash Script equivalent KSH script?

I always find BASH easier than ksh. At my home, i have written this bash script. I am finding it hard to write its equivalent in ksh, any suggestions?

Code:
######################################
#return seconds since `00:00:00 1970-01-01 UTC' (a GNU extension)
######################################
date2stamp () {
    date --utc --date "$1" +%s
}
######################################
# finds number of days between two times
# dateDiff -d "23:59:59" "16:15:07"
# number of hours between two times
# dateDiff -h "23:59:59" "16:15:07"
# number of minutes between two times
# dateDiff -m "23:59:59" "16:15:07"
# number of seconds between two times
# dateDiff -s "23:59:59" "16:15:07"
######################################
dateDiff (){
    case $1 in
        -s)   sec=1;      shift;;
        -m)   sec=60;     shift;;
        -h)   sec=3600;   shift;;
        -d)   sec=86400;  shift;;
        *)    sec=86400;;
    esac
    dte1=$(date2stamp $1)
    dte2=$(date2stamp $2)
    diffSec=$((dte2-dte1))
    if ((diffSec < 0)); then abs=-1; else abs=1; fi
    return $((diffSec/sec*abs))
}

dateDiff -h "23:59:59" `date '+%T'`


Last edited by vino; 03-09-2010 at 12:24 AM.. Reason: added code tags
# 2  
Old 03-09-2010
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk script Equivalent .

Hello. I wrote some code for an awk command but I want to learn to turn it into an awk script but am stuck. I have a file (data.csv) that has the following data: ADD,1,3,5,8,10,11,54 SUB,1,2,3,4 ADD,15,18,21,42,37 ADD,1,1,1,0,0,3,16 ADD,4,1,8,0,4,6,13,16,17,20,8,6,4 SUB,13,8If the line... (5 Replies)
Discussion started by: Eric7giants
5 Replies

2. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

3. Shell Programming and Scripting

How to run ksh script in bash shell?

Hi All, I have few bash shell scripts which depends on one Ksh shell script. When i run bash shell scripts, it shows error as bad interpretor : ksh no such bad file or directory. When i tried to install ksh shell, it is not downloading too. If I remove !/bin/ksh command in starting line of the... (14 Replies)
Discussion started by: Karthik03
14 Replies

4. Shell Programming and Scripting

Expect : what is the equivalent to ksh if -s

In Ksh to check if file exists and is non zero .. if ; then echo "Error $FILE does not exists!" else echo "$FILE found!" fi Cant seem to find the Expect equivalent .... Any help is greatly appreciated. (2 Replies)
Discussion started by: popeye
2 Replies

5. Shell Programming and Scripting

What is the ksh equivalent to bash's "history -c" command?

Hi, What is the korn shell equivalent of bash shell's "history -c" command? I do know, how to clear the history list in ksh, I can do the following: > ~/.sh_historybut still, I am interested to know the single one line command as 'history -c' gives error on my ksh (1 Reply)
Discussion started by: royalibrahim
1 Replies

6. Linux

Need SCP script equivalent to FTP script .

Hi, Currently i'm using the folllowing FTP acript and its working. echo "open $server" > ftp_file echo "user $user $password" >> ftp_file echo "cd $remote_dir" >> ftp_file echo "lcd $local_dir" >> ftp_file echo "put $file">> ftp_file echo "bye" >> ftp_file ftp -nv < ftp_file I've... (1 Reply)
Discussion started by: vickramshetty
1 Replies

7. Shell Programming and Scripting

equivalent of backspace in ksh

Hello All, What would be the equivalent of backspace key in the korn shell. My scenario is: I am trying to install a product..and it comes out with a Licence Agreement screen, When I manually enter backspace key..I am able to get out of the whole agreement message to a point to type Agree A) or... (2 Replies)
Discussion started by: solaix14
2 Replies

8. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

9. Shell Programming and Scripting

awk equivalent script

Hi All, I need a script that prints a blank line after finding that the next lines first field doesn't match the current lines first field. I really want to do this in awk to improve my own knowledge but the best I can come up with is a bash script. I'd finally like to understand how awk... (10 Replies)
Discussion started by: pondlife
10 Replies

10. Shell Programming and Scripting

what is ksh equivalent of bash echo -n ?

Hi folks, I need to stop printing a new line after echoing a string in KSH. i know bash provides echo -n "string" what is the ksh equivalent for this ? (3 Replies)
Discussion started by: mudhireddy
3 Replies
Login or Register to Ask a Question