Hi all
Below code works in bash but it is not working in ksh.
enddate=`date -d "$enddate + $i day" "+%Y_%m_%d"`
Please help me how it works in ksh
Thanks
Hi all
Below code works in bash but it is not working in ksh.
enddate=`date -d "$enddate + $i day" "+%Y_%m_%d"`
Please help me how it works in ksh
Thanks
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.
startdate="${1//_/-}" # change underscores into dashes
Use sed instead to perform search and replace.
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?
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:
while [ 1 ]
It will work, but will use "test" to do so. Instead
while :
will do the same with less resources used.
I hope this helps.
bakunin
@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.
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
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).
I changed
#!/bin/bash
to
#!/bin/ksh -xv
and
I got the error called
startdate="${1//_/-}"
:Bad substitution
Please help me
That is exactly what I said in my post before.
You have 2 options here:
#!/bin/ksh93
startdate=$( echo $1 | sed 's/_/-/g' )
-d is not working in ksh.
enddate=`date -d "$enddate + $i day" "+%Y_%m_%d"`
If i remove -d from the above line igot the error called bad conversion
elixir_sinari already mentioned in his post that if you do not have GNU date
then you will not be able to use -d
option and perform date arithmetic.
I recommend you to take a look at this thread for alternatives.