Operating System - HP-UX
1827279 Members
3374 Online
109717 Solutions
New Discussion

Ksh script calling Csh script !!

 
Chris Fung
Frequent Advisor

Ksh script calling Csh script !!

Hi there,

Because of some political issue, I need to write a Ksh menu program to call some Csh scripts.....

However, I have difficulties to get the return code returned by Csh.....

Could anyone give me some examples for this question !

Many thanks,

Chris,
4 REPLIES 4
Ramkumar Devanathan
Honored Contributor

Re: Ksh script calling Csh script !!

Chris,

I just tried out this -

$ cat /tmp/a.sh
#!/usr/bin/ksh
csh c.sh
if [[ $? -eq 0 ]]; then
echo "c.sh exited with 0 return value"
else
echo "c.sh exited with non-zero return value"
fi
# EOF

$ cat /tmp/c.sh
#!/usr/bin/csh
exit 1
# EOF

I am able to get the return values perfectly when i run a.sh with the call to c.sh as follows -

/tmp/c.sh or csh /tmp/c.sh.

It'd probably help if you could attach the scripts here.

HTH.

- ramd.
HPE Software Rocks!
Donny Jekels
Respected Contributor

Re: Ksh script calling Csh script !!

Chris,

$? will return all exit codes.

however if your c.sh script return more values such as variables.

then you want to consider this

c.sh | read LINE

echo $LINE

then you you can work from there.

one of my c.sh scripts for instance return 18 variables.

in ksh you can read them as

c.sh | read VAR[0] VAR[1] ... VAR[17]

echo $VAR[*] or echo $VAR[@]

l8r
peace
Donny

"Vision, is the art of seeing the invisible"
Michael Steele_2
Honored Contributor

Re: Ksh script calling Csh script !!

Something not right here. I don't believe you should be seeing this.

'crontab' is csh for example.

Got any lines in between the executing command and the test?

Try this:

command1
STAT1=$?

command2
STAT2=$?

etc.
Support Fatherhood - Stop Family Law
Bill Hassell
Honored Contributor

Re: Ksh script calling Csh script !!

*ALL* scripts should start with the 'courtesy loader' directive so the shell will run the correct interpreter. For example:

#!/usr/bin/csh
...csh code...

or

#!/usr/bin/ksh

#!/opt/perl/bin/perl

and so on.

Note that there is only ONE return code for any process or script, the numeric value returned when it finishes (and accessible via $? in ksh or other POSIX shells). For additional values, the script must output these values as stdout or stderr and the calling script read these values.

If the csh scripts change the environment by setting certain variables, these scripts must be rewritten to return the changes as stdout or stderr since executing a script in place (called 'sourcing' by using the dot . shell construct) requires the script to be written in the same language as the invoking shell (ksh in your case).


Bill Hassell, sysadmin