unix functions


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers unix functions
# 1  
Old 03-24-2009
unix functions

Hi All,

i have two functions in my script.

Code:
question()
{
num=`ps -e | grep ps | awk -F" " '{print $1}'` 
qno=`expr $num % 10`
grade=grade1 
cat grade1/$qno
answer ${grade} ${qno} 
}
answer()
{
grade=$1
qno=$2
ansno=`wc -l $grade/ans/$qno | cut -d' ' -f1`
j=0 
while [ $j -lt $ansno ]
do
echo select your answer 
read ans[$j]

echo "do you want to select one more answer?"
read ch
if [ $ch != y ]
then
break;
fi
j=`expr $j + 1`
done
k=0 
exec < $grade/ans/$qno
while read line
do
echo line=$line 
while [ $k -lt $ansno ]
do
if [ ${ans[$k]} = $line ]
then
echo "equal"
else
echo "not equal"
fi
k=`expr $k + 1`
done 
done 
}

i am calling question function 3 times in a loop. for the 1st times it works fine, 2nd and 3rd time this will not take input for ans[$j]
can you please help?
thanks

Last edited by Yogesh Sawant; 03-25-2009 at 03:28 AM.. Reason: added code tags
# 2  
Old 03-24-2009
try changing:

exec < $grade/ans/$qno
while read line
do
.
.
.
done

to:

while read line
do
.
.
.
done < $grade/ans/$qno
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run multiple functions in Background in UNIX Shell Scripting?

Hi, I am using ksh , i have requirement to run 4 functions in background , 4 functions call are available in a case that case is also in function, i need to execute 1st function it should run in background and return to case and next i will call 2nd function it should run in background and... (8 Replies)
Discussion started by: karthikram
8 Replies

2. Shell Programming and Scripting

How to execute functions or initiate functions as command line parameters for below requirement?

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line if then... (8 Replies)
Discussion started by: saku
8 Replies

3. Shell Programming and Scripting

Recursive functions in Unix

Hi Guys, Is there a way to write a recursive function in unix? Thanks for your help in advance, Regards, Magesh. (1 Reply)
Discussion started by: mac4rfree
1 Replies

4. Shell Programming and Scripting

functions

I have korn shells where I want to create a function passing $1 to a function , determine my $STAT_ENV value, set the paths and return the paths for STATSH,STATPRM,STATSQR,STATSQL,STATCTL TO BE USED IN THE UNIX SCRIPT THE CALLED THE fucnction in the first place. Can someone tell me the best... (2 Replies)
Discussion started by: TimHortons
2 Replies

5. Programming

Standard UNIX functions

Hi everybody, first of all i apologize if my thread's title doesn't make much sense,but i coudn't find a more appropriate name :) Then i apologize about my question,which probably will sound trivial for you :) :) I am working on a program which is being tested in Linux but the final target is... (2 Replies)
Discussion started by: Zipi
2 Replies

6. Programming

Similar functions in unix

Hi, I am windows programer. I have very basic knowledge of Unix OS. I have written an application in Windows which consists of Win32 API namely WideCharToMultiByte(..) and MultiByteToWideChar(..). I am interested to deploy my application in unix platform henceforth I need to know IS... (1 Reply)
Discussion started by: dayakarr
1 Replies

7. Shell Programming and Scripting

Excuting UNIX Functions under several username and host

Hi, I am facing a issue in one of my script, Please help me on the same. Below I have the example. Example: I have two functions(host(),user()) in a single file named test1.ksh File Name: test1.ksh host () { HOST=`hostname` echo... (1 Reply)
Discussion started by: samvino
1 Replies

8. Programming

newbie to unix programming in C, needed a few simple prgs on these functions!

Hi all, I am a newbie to unix programming using C.. So i would like to have a few simple C programs to start off with.. I wanted programs on learning , abort,kill and raise,alarm and pause,I would also like to know how to use the vfork() in a prg It would be really great if i can have... (1 Reply)
Discussion started by: wrapster
1 Replies

9. Shell Programming and Scripting

Use of functions

Hi my shell is tcsh can I have functions in my shell scripting? Is the below shell script correct. Can I have two functions and call one of them as required. ---------- echo "functions" f1 f1 () { echo "hello" } f2 () (1 Reply)
Discussion started by: amitrajvarma
1 Replies

10. Shell Programming and Scripting

Regarding functions

Hi, I have a function or script like this. show() { echo "Hi" } | tee -a log show This creates a logfile and prints Hi in it. Now when I try to do the same for sql like this: show() { sqlplus -s scott/tiger<<! select * from details; ! } | tee -a log show Then it gives me a... (2 Replies)
Discussion started by: sendhilmani
2 Replies
Login or Register to Ask a Question