Bash to ksh problem | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Bash to ksh problem

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-20-2013
pmreddy pmreddy is offline
Registered User
 
Join Date: Apr 2012
Last Activity: 3 July 2013, 2:31 AM EDT
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Bash to ksh problem

Hi all

Below code works in bash but it is not working in ksh.


Code:
enddate=`date -d "$enddate + $i day" "+%Y_%m_%d"`

Please help me how it works in ksh

Thanks

Last edited by pmreddy; 01-21-2013 at 04:50 AM..
Sponsored Links
    #2  
Old 01-20-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 17 April 2014, 8:35 PM EDT
Location: Galactic Empire
Posts: 3,282
Thanks: 227
Thanked 1,157 Times in 1,094 Posts
Replace shebang #!/bin/bash to #!/bin/ksh -xv (set xtrace & verbose) and run the code to reveal lines that are not KSH compliant.

For example, I see you are using string search and replace which I guess is not supported in KSH.

Code:
startdate="${1//_/-}"  # change underscores into dashes

Use sed instead to perform search and replace.
Sponsored Links
    #3  
Old 01-20-2013
elixir_sinari's Avatar
elixir_sinari elixir_sinari is offline Forum Advisor  
Gotham Knight
 
Join Date: Mar 2012
Last Activity: 18 April 2014, 12:09 AM EDT
Location: India
Posts: 1,412
Thanks: 100
Thanked 495 Times in 472 Posts
Quote:
Originally Posted by bipinajith View Post
For example, I see you are using string search and replace which I guess is not supported in KSH.
ksh does support it. But only ksh93 versions.

@OP: Which ksh version are you using? Are you running this on some machine not having GNU date installed?
    #4  
Old 01-20-2013
bakunin bakunin is online now Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 18 April 2014, 9:02 AM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 3,919
Thanks: 39
Thanked 671 Times in 533 Posts
I'd also replace the "echo"s with "print"s. "print" is a built-in command in ksh, while "echo" isn't.

What is equally ugly in ksh and in bash is this:


Code:
while [ 1 ]

It will work, but will use "test" to do so. Instead


Code:
while :

will do the same with less resources used.

I hope this helps.

bakunin
Sponsored Links
    #5  
Old 01-20-2013
Chubler_XL's Avatar
Chubler_XL Chubler_XL is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 17 April 2014, 12:50 PM EDT
Posts: 2,601
Thanks: 94
Thanked 804 Times in 757 Posts
@Bakunin, can you site a version of ksh where echo is not builtin?

I have 11/16/88, 12/28/93 and mksh 41 and it appears to be builtin in all of these.
Sponsored Links
    #6  
Old 01-20-2013
bakunin bakunin is online now Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 18 April 2014, 9:02 AM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 3,919
Thanks: 39
Thanked 671 Times in 533 Posts
It might be built in but this is not required by the standard. The standard output command in ksh is "print" and if you use "echo" the shell executes "/bin/echo" if it is not built in. In the AIX ksh (a ksh88) this used to be so, but to be honest i haven't checked that lately.

bakunin
The Following User Says Thank You to bakunin For This Useful Post:
Chubler_XL (01-20-2013)
Sponsored Links
    #7  
Old 01-20-2013
Chubler_XL's Avatar
Chubler_XL Chubler_XL is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 17 April 2014, 12:50 PM EDT
Posts: 2,601
Thanks: 94
Thanked 804 Times in 757 Posts
Thanks, that might explain why a lot of the old AIX ksh scripts we have around here use print (I've always replaced them with echo or printf, whenever making updates - just because it's more portable).
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Ksh to bash then back to ksh sukhdip Shell Programming and Scripting 4 01-31-2012 03:09 AM
Typeset conversion problem from ksh to bash kanagaraj Shell Programming and Scripting 3 03-05-2010 10:14 AM
bash preferred or ksh with bash features mrwatkin UNIX for Dummies Questions & Answers 2 06-17-2009 01:19 PM
bash & Ksh loop problem zedex Shell Programming and Scripting 1 04-08-2009 09:15 AM
bash and ksh: variable lost in loop in bash? estienne Shell Programming and Scripting 2 08-25-2008 02:09 PM



All times are GMT -4. The time now is 09:09 AM.