Operating System - HP-UX
1834394 Members
2158 Online
110066 Solutions
New Discussion

Re: KSH script wrong behaviour

 
Enrico Venturi
Super Advisor

KSH script wrong behaviour

Hi all,
I'm using the KSH in HP-UX 10.20 on a HP B2000 machine.
In a KSH script A I call the function B (which is declared in a file executed in the header of A) then B calls the KSH script C.
It seems impossible but when C ended the control flow is returned not to B but to A.
A and C are different files.
B is a function contained in an environmental file which is executed before starting C.
It seems that A calls B (function) at line 100; B calls C at line 50 of B; when C ends the control returuns to A-line 101 rather than to B- line 51 ... The problem are:
* the instructions after B-line 50 are NOT executed
* the "$?" (return code) is undefined ... or better: it's 151 (what does it men??)

Have you any ideas?

thank you very much
6 REPLIES 6
Steven Sim Kok Leong
Honored Contributor

Re: KSH script wrong behaviour

Hi,

I wasn't able to simulate your problem. Would you want to post your script up?

My test results are as follows. Notice that "echo d" gets executed when c.ksh finishes execution.

=============================
$ ./a.ksh
a
b
c
d
e
f
g

$ cat a.ksh
#!/usr/bin/ksh

a ()
{
echo b
c.ksh
echo d
}

echo a
a
echo e
echo f
echo g

$ cat c.ksh
echo c
===========================

Hope this helps. Regards.

Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com
Deepak Extross
Honored Contributor

Re: KSH script wrong behaviour

<>
What do you mean by "environmental file"?

It is well known that if there is any erroneous command mentioned in a startup file (.profile / .login), further processing of the startup file is aborted.

Is your problem related to this?
Enrico Venturi
Super Advisor

Re: KSH script wrong behaviour

I forgot to write that USUALLY (i.e. with HP-UX 11.0) the scripts work fine!!
It seems that when the B function is called and it executes a remsh, something strange happens then the remaining of B is not executed.
I enclose the source files: A = ManualSwitch
B = IsReachable, C = remoteCommand.

With "environmental file" I mean a file which is executed by the A / C scripts ... A starts executing B, which contains the relevant function (IsReachable)

thanks to everybody
Deepak Extross
Honored Contributor

Re: KSH script wrong behaviour

Hi,

In script C, try replacing "exit $rem_ret"
with
"return $rem_ret"

From the man page of exit,
"...exit() terminates the calling proces..."
Probably this is killing your ptocess B.
Enrico Venturi
Super Advisor

Re: KSH script wrong behaviour

the "exit $rem_ret" is correct because the C script isn't a function ... it's executed as a process then it's correct it exit()
Robin Wakefield
Honored Contributor

Re: KSH script wrong behaviour

Hi,

You may want to look at putting the "-n" switch in your remsh command to stop it inadvertently sucking in input from your script.

This has often caused problems with scripts that remsh to other servers.

Rgds, Robin.