Question about Korn Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question about Korn Shell
# 8  
Old 11-04-2003
If I can use the "do" statement, how would I phrase it? I tried the do command in a simple script. It doesn't work.

print -n "Y/N "
read ans
if [ ans = Y ]; do
my_function
else
echo "NOT TRUE"
fi

my_function () {
echo "INSIDE MY FUNCTION"
}

I get the error
./test[4]: 0403-057 Syntax error at line 5 : `do' is not expected.
# 9  
Old 11-04-2003
if [ $ans = Y ] ; then
# 10  
Old 11-04-2003
If I do that, would it come back to where it was after execution of the paragraph like a "do" statement? I really would like to do something like a "perform" statement in cobol.

Thank you.
Latha
# 11  
Old 11-04-2003
Cobol's perform statement can do a lot. But invoking a function in ksh would be very close to "perform my_function." in cobol.

That function Optimus_P posted is legal, but it really should have a "return 0" as the last statement. But even without a return, you come back when the function is finished. Invoking a function is close to invoking another shell script.
# 12  
Old 11-04-2003
When I tried the "do" statement, I received an error message.
What is the right way of coding a function? I am going to Barnes & Nobles today to look for a korn shell book, but in the mean time can you give me a hint?

Thank you.
Latha
# 13  
Old 11-04-2003
Code:
#! /usr/bin/ksh
my_function () {
     echo "INSIDE MY FUNCTION"
     return 0
}

print -n "Y/N "
read ans
if [ $ans = Y ]; then
      my_function
else
      echo "NOT TRUE"
fi

echo  approaching the end of the script
my_function
exit 0

The return and the exit are not strictly needed, but when you ask me, you get it my way. Also I to make sure that you realize that you can invoke a function anywhere, not just inside an "if" statement. So I put in a 2nd call.
# 14  
Old 11-05-2003
Thank you Perderabo

Thanks so much. I tried it and it works fine. I am getting a Korn Shell book (Possibly by O'Reilly) in a few days (when it has to go thru purchasing dept, it might take a few days). I have put in my request.

Thank you for explaining the second call. I understand what you did there. It is nice to know that you can call a function from different spots of a script. That will come in handy for me as well.

This site is just great, and people are willing to help. I can't thank you enough.

Latha
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

korn shell remove files question

how do you show each filename in a giving directory and delete the specific file in korn script i was thinking using ls rm ? but i cant make it work (0 Replies)
Discussion started by: babuda0059
0 Replies

2. Shell Programming and Scripting

Question about a simple Korn script

Hi to everybody! I want to write a simple script in ksh that decrypts and encrypts using the DES algorithm. There is no builtin function in UNIX : i have found only a function in openssl but i don't understand how to use it. The script must accept in input the plaitext and the DESKEY in... (2 Replies)
Discussion started by: kazikamuntu
2 Replies

3. AIX

AIX 4.2 Korn shell and grep question

Ho do I find out the verion of the Kron shell on my client`s system ? There is no one to ask. They are not knowledged enough (hard to believe but yes). Also, on that AIX 4.2, I am trying to figure out how to do a grep using a search patter like below but does not seam to work. The '*' do... (11 Replies)
Discussion started by: Browser_ice
11 Replies

4. Shell Programming and Scripting

Korn shell and awk question

I am modifying a Korn shell script in using the Exceed (Solaris 10 environment). My task is to read in a .txt file with dates arranged like this (01-Sep-2006). I am to read each line and take the dates, compare them to a benchmark date and depending on if it is older than the date or the date and... (6 Replies)
Discussion started by: mastachef
6 Replies

5. Shell Programming and Scripting

korn shell question

Hi all, I am trying to tweak my ksh , i am running V: Version M-11/16/88i I have my Backspace and up/down arrows working using the following code in my ~/.profile file. set -o emacs alias __A=$(print '\020' ) alias __B=$(print '\016' ) alias __C=$(print '\006' ) alias __D=$(print... (4 Replies)
Discussion started by: mich_elle
4 Replies

6. Shell Programming and Scripting

Korn Shell Coprocess Performance Question

I am wracking my brains over this. I am trying to use a Korn Shell script to execute an Oracle PL/SQL procedure, using the Oracle command line interface (sqlplus). The script starts sqlplus in a coprocess, and the two processes communicate using a two-way pipe. The bgnice option is off, so both... (8 Replies)
Discussion started by: Mark Puddephat
8 Replies

7. Shell Programming and Scripting

Korn Shell Loop question

I'm needing help with assigning variables inside a while loop of ksh script. I have an input text file and ksh script below and I'm trying to create a script which will read the input file line by line, assign first and second word to variables and process the variables according to the contents. ... (4 Replies)
Discussion started by: stevefox
4 Replies

8. Shell Programming and Scripting

how to convert from korn shell to normal shell with this code?

well i have this code here..and it works fine in kornshell.. #!/bin/ksh home=c:/..../ input=$1 sed '1,3d' $input > $1.out line="" cat $1.out | while read a do line="$line $a" done echo $line > $1 rm $1.out however...now i want it just in normal sh mode..how to convert this?... (21 Replies)
Discussion started by: forevercalz
21 Replies

9. Shell Programming and Scripting

AWK question in the KORN shell

Hi, I have two files with the following content: gmrd.txt 235649;03;2563;598 291802;00;2563;598 314634;00;235649;598 235649;03;2563;598 393692;00;2563;598 411805;00;2563;598 411805;00;2563;598 235649;03;2563;598 414037;00;2563;598 575200;00;2563;598 70710;00;2563;598... (11 Replies)
Discussion started by: penfold
11 Replies

10. Shell Programming and Scripting

Question variables Korn

I'm using the following command to test for certain characters in a script echo "${1}" | grep '\$' if (( ${?} == 0 )) then testing this script on the command line I have ksh -x script1.sh "xxxx$xxxx" this works fine but when I want to use ksh -x script1.sh "xxxx $xxx" the... (1 Reply)
Discussion started by: frank
1 Replies
Login or Register to Ask a Question