ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh
# 8  
Old 02-09-2015
Dears

kindly , thank you very much for both of you, I am very happy to see the prompt reply from you. today I registered in this website am sure it wont make me regret ...I am new in ksh scripting that is why I wanted to write script to add X number with date for example
20140129 +9 days the result will be 20140207 I saw it difficult because as it has been mentioned by Mr. Don i should consider normal year,leap year and we have 12 months but march is only 28 days i hope my comment is clear to you thanks again ...currently I am using software called admin ksh for windows because i have windows operating system.

---------- Post updated at 02:38 PM ---------- Previous update was at 02:28 PM ----------

Hello Ravinder,

after your posted link i found below i my required script but i dont understand it very well
Code:
cat script.ksh
echo $1 | awk -vs1="01" -vs2="03" -vs3="12" '{
                                                if(length($0)>8){
                                                                        print "Wrong Input!!";
                                                                        exit
                                                                }
                                                YEAR=substr($0,1,4);
                                                YEAR+0;
                                                MONTH=substr($0,5,2);
                                                MONTH+0;
                                                DATE=substr($0,7,2);
                                                DATE+0;
                                                split("31 29 31 30 31 30 31 31 30 31 30 31", W," ");
                                                if(DATE==s1 && MONTH==s1){
                                                                                YEAR=YEAR-1;
                                                                                MONTH=12;
                                                                                DATE=31;
                                                                                print YEAR MONTH DATE
                                                                         }
                                                else if(DATE==s1 && MONTH >= s1 && MONTH <= s3){
                                                                                MONTH=MONTH-1;
                                                                                W[2]=(YEAR%4!=0)?28:29;
                                                                                print YEAR MONTH W[MONTH]
                                                                                                }
                                                else {
                                                                                DATE=DATE-1;
                                                                                printf("%04d%02d%02d\n", YEAR, MONTH, DATE);
                                                     }
                                              }'

# 9  
Old 02-09-2015
I can't comment on "admin ksh for windows", but above script doesn't have anything to do with ksh. It is pure awk for subtracting one day from the input supplied. It takes into account crossing New Year, and, partly, leap years plus some error checking. It does not add any number of days nor subtract more than one day.
Still it can serve as a starting point for your work on a ksh script to achieve what you want.

And, please be clear what you want - ksh (as in the title) or awk (as in post #1)?

Last edited by RudiC; 02-09-2015 at 09:46 AM..
# 10  
Old 02-12-2015
Dear RudiC,

kindly , I want script to calculate date that is all more detail when you have 20150129 + 10 days the result will be 20150208. if you can provide me a script for that thank you very much.
# 11  
Old 02-12-2015
Hello shaho87,

This is a forum, a place where we all are here to learn from each other. I have posted my script previously in POST#6 and requested you to try something with it, could you please try something with that script and let us know the issues/queries you face so that we can help you in that. By this way we can learn more and help more to each other which is the main aim of this forum. We all are open to do mistakes(consider my stetement in dev/testing/personal environments only) and learn from them, there is a famous quote for same.
Quote:
Doing miskate first time is not a mistake, but NOT learning from mistakes is a BIG mistake.
Hope this helps.

Thanks,
R. Singh
# 12  
Old 02-15-2015
Hello all

could you please some one explain below for me? thanks
Code:
_std_input_str=`dd count=$CONTENT_LENGTH bs=1 2> /dev/null`"&"
eval $(echo $_std_input_str |awk -F"&" '{for (i=1;i<NF;i++) print $i}')


Last edited by vbe; 02-15-2015 at 04:16 PM.. Reason: code tags
# 13  
Old 02-16-2015
Please open a new thread for a new request!

Above snippet looks strange with no context set.
It assigns $CONTENT_LENGTH bytes read from stdin plus a "&" char to the variable, wherever stdin is redirected to.
Then, assuming a field separator "&", it splits that text's fields into single line words, and executes those words using eval (pls be aware that using eval is deprecated as is may turn out to be dangerous).

So, curtly, it executes every word read from stdin, regardsless of its possible damage to your system.
# 14  
Old 02-16-2015
Quote:
Originally Posted by RudiC
... ... ... and executes those words using eval (pls be aware that using eval is deprecated as is may turn out to be dangerous).

... ... ...
The eval command has not been deprecated in the standards. It is still a mandatory special built-in utility in the shell in shells conforming to the POSIX standards and the Single UNIX Specifications.

However, I agree that it needs to be used judiciously. In general, eval should not be used to evaluate (or execute) user supplied strings.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help with ksh

I have the following file: one two three four man women yes no place togo bad sleep I need to move all lines that have only two words(columns) in a separate file and the rest in a separate file... I used : for $linecont in $(cat $filename); do echo $linecont > temp line1='cat... (7 Replies)
Discussion started by: daimne
7 Replies

2. Shell Programming and Scripting

ksh help

Hi, I have command like this with ooutput : unix>tnsping abc TNS Ping Utility for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Production on 17-AUG-2011 17:06:11 Copyright (c) 1997, 2007, Oracle. All rights reserved. Used parameter files: /opt/oracle/network/admin/sqlnet.ora ... (19 Replies)
Discussion started by: talashil
19 Replies

3. Shell Programming and Scripting

different behaviour for ksh and ksh -x

I'm getting different behaviour when executing below script in debug option. $ cat ss.ksh ff=$(pwd) echo " ff : $ff" $ ksh ss.ksh ff : /tmp $ ksh -x ss.ksh + + pwd ff= + echo ff : ff : I was getting this behaviour in my actuall script i'm able to reproduce this in simple script... (4 Replies)
Discussion started by: luckybalaji
4 Replies

4. UNIX for Dummies Questions & Answers

Difference Between executing llike ./myscript.ksh and . ./myscript.ksh

Hi , What is the diffence between executing the script like ./myscript.ksh . ./myscript.ksh I have found 2 difference but could not find the reason 1. If i export a variable in myscript.ksh and execute it like . ./myscript.ksh the i can access the other scripts that are present in... (5 Replies)
Discussion started by: max_hammer
5 Replies

5. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

6. Shell Programming and Scripting

Need help on ksh

1. Script using bash #!/bin/bash a=4294967296 (( b=$a / 2 )) echo "$a" echo "$b" *** output *** 4294967296 2147483648 2. Script using ksh #!/bin/ksh a=4294967296 (( b=$a / 2 )) echo "$a" echo "$b" *** output *** 4294967296 (3 Replies)
Discussion started by: gautam.shrestha
3 Replies

7. Shell Programming and Scripting

Help with KSH

Hi, I need some help with the Ksh scripting.... I have a Script call Mail.ksh which calls Crank.ksh which calls Readdates.ksh whoch calls mindiff.ksh the output of mindiff.ksh and Readdates.ksh are wirtten to a text file... Here is how each file is called or executed... ./Mail.ksh 30... (3 Replies)
Discussion started by: bhagya2340
3 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

tracing a ksh script within a ksh script

I normally trace a script with the ksh -x <script name> and redirect strderr to file. But if you have a script like the examble below...... vi hairy bear=`grep bear animals` if then ksh more_animals fi If I ksh -x hairy it won't trace "more_animals" unless I put a -x in it. Is... (1 Reply)
Discussion started by: shorty
1 Replies

10. Shell Programming and Scripting

executing a ksh script from another ksh script

Hi, I'm new to unix scripting.How can i call a script from another script. I have a.ksh and b.ksh .I have to call b.ksh from a.ksh after it is successfully exceuted. I tried using #!/bin/ksh -x in a.ksh and at the end i have used /path/b.ksh My problem is it is executing only a.ksh.it... (6 Replies)
Discussion started by: ammu
6 Replies
Login or Register to Ask a Question