Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ERRNO 1

Status
Not open for further replies.

tof

MIS
Jul 26, 2001
7
0
0
FR
Hello,
i have a little problem with the ERRNO variable.
I am create this script ( named test.sh ) :
#!/bin/ksh
export ERRNO=0
echo "\$ERRNO : $ERRNO"
rm -f /tmp/file.txt
echo "\$ERRNO : $ERRNO"
. /tmp/essai.sh

( The /tmp/file.txt does not exist )


And in /tmp/essai.sh :
#!/bin/ksh
echo "\$ERRNO : $ERRNO"


When i execute the test.sh script :
ERRNO : 0
ERRNO : 2
ERRNO : 25

So i lost the ERRNO variable when i invoquing an other script (in the same shell !)!
There is a solution : put the ERRNO variable in an other variable before invoking /tmp/essai.sh, but i don't want.
I want use ERRNO (ERRNO=2) in the /tmp/essai.sh script.
Do you know a solution (pehaps with an option of ksh or the set command )

Thanks.


 
ERRNO is a variable which is also maintained by the shell, so you may set it's value, but the shell may change it as a result of a subsequent command.

Are you intentionally using ERRNO as a variable name, or can you change it?

Greg.
 
In fact, i want the last system error (in the script it is 2 because file.txt does not exist), and i want use it in a second script (/tmp/essai.sh). But, in the second script, it is automatically 25.

Thanks.
 
try assigning the value of $ERRNO to another variable and examining that in the other script

rm -f /tmp/file.txt # doesn't exist
export MY_ERRNO=$ERRNO
./my_other_script

and in ./my_other_script

rm -f /tmp/file1.txt # did exist
print "ERRNO=$ERRNO"
print "MY_ERRNO=$MY_ERRNO"
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Hello,
i am agree with you MikeLacey, the only solution i find is to put ERRNO in an exporting variable and use it in the other script.
But i don't understand why, when i call the script /tmp/essai.sh, ERRNO is already in 25.
 
It looks to me like ERRNO is set to 25 on execution of a shell script. If you were to echo $ERRNO at the start of test.sh, before you do the export ERRNO=0 you would find that it is set to 25 ... the same value as it has when you execute essai.sh.

Greg.
 
It is exact ERRNO is set to 25 at the begin of test.sh.
But, is it normal ? and there is a solution if i don't want ERRNO set to 25 ?
 
There is no way to avoid ERRNO being set by the shell. ERRNO is an internal shell variable and is not meant to be set by a user script. I would go with Mikes solution of using your own exported variable.

The man page for ksh says

ERRNO - The value of errno as set by the most recently failed system call. This value is system dependent and is intended for debugging purposes.


Do a man ksh to see the description of the ERRNO variable, and the other variables maintained by the shell.

Greg.
 
So, the only solution is to export a variable before calling a script.

Thanks grega,MikeLacey
 
Yes. That's how you make a value available to all shells - export it. If ERRNO wasn't an internal shell variable and you could use the name for your own variable, you'd still have to export it from test.sh to make it visible in essai.sh.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top