Unix Shell - Exit Status Not Returned?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > April 2005 > Exit Status Not Returned?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Exit Status Not Returned?
absinth

2005-04-29, 8:09 am

Can someone help me with this in KSH and tell me why the exit status is
not returned?

Why is "haha" printed?

#!/bin/ksh

getNoGlobalProc()
{
local a=`ls sdfafa`

if [[ $? -ne 0 ]]; then
echo "$SCRIPTNAME : $LINENO : Could not obtain global number of
processes running"
return 1
fi

echo "haha"

return 0
}

getNoGlobalProc

absinth

2005-04-29, 8:09 am

Follow up 'sdfafa' doesn't exist I used it as an example of a garbage
program.

Chris F.A. Johnson

2005-04-29, 8:09 am

On Fri, 29 Apr 2005 at 05:55 GMT, absinth wrote:
> Can someone help me with this in KSH and tell me why the exit status is
> not returned?
>
> Why is "haha" printed?


Because the command (local) succeeded.

> #!/bin/ksh
>
> getNoGlobalProc()
> {
> local a=`ls sdfafa`
>
> if [[ $? -ne 0 ]]; then
> echo "$SCRIPTNAME : $LINENO : Could not obtain global number of
> processes running"
> return 1
> fi
>
> echo "haha"
>
> return 0
> }
>
> getNoGlobalProc




--
Chris F.A. Johnson <http://cfaj.freeshell.org>
========================================
==========================
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/ssr.html>
absinth

2005-04-29, 8:09 am

Is there a way to make the variable local in KSH and also have the exit
status of the command substitution returned?

Chris F.A. Johnson

2005-04-29, 8:09 am

On Fri, 29 Apr 2005 at 06:41 GMT, absinth wrote:
> Is there a way to make the variable local in KSH and also have the exit
> status of the command substitution returned?


[Please quote enough of the article you are replying to to give the
context.]

local a
a=`ls sdfafa`


--
Chris F.A. Johnson <http://cfaj.freeshell.org>
========================================
==========================
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/ssr.html>
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com