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 05: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: 25 November 2014, 4:24 PM EST
Location: Galactic Empire
Posts: 3,389
Thanks: 236
Thanked 1,210 Times in 1,136 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  
Registered User
 
Join Date: Mar 2012
Last Activity: 9 October 2014, 4:50 PM EDT
Location: India
Posts: 1,412
Thanks: 101
Thanked 496 Times in 473 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 offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 25 November 2014, 9:32 AM EST
Location: In the leftmost byte of /dev/kmem
Posts: 4,337
Thanks: 45
Thanked 839 Times in 662 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: 25 November 2014, 3:59 PM EST
Posts: 3,021
Thanks: 114
Thanked 969 Times in 908 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 offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 25 November 2014, 9:32 AM EST
Location: In the leftmost byte of /dev/kmem
Posts: 4,337
Thanks: 45
Thanked 839 Times in 662 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: 25 November 2014, 3:59 PM EST
Posts: 3,021
Thanks: 114
Thanked 969 Times in 908 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 04:09 AM
Typeset conversion problem from ksh to bash kanagaraj Shell Programming and Scripting 3 03-05-2010 11:14 AM
bash preferred or ksh with bash features mrwatkin UNIX for Dummies Questions & Answers 2 06-17-2009 02:19 PM
bash & Ksh loop problem zedex Shell Programming and Scripting 1 04-08-2009 10:15 AM
bash and ksh: variable lost in loop in bash? estienne Shell Programming and Scripting 2 08-25-2008 03:09 PM



All times are GMT -4. The time now is 05:55 PM.