One last command after "exit 1"?

One last command after "exit 1"?

am 15.02.2006 17:10:10 von alfa_44

Hi,

I have a problem in a script that I can't seem to resolve. I'm writing a
series of install scripts, and among other things, I have a fancy little
function check_status... you've ever seen Gentoo's or Mandrake's boot
scripts, with all those fancy little [ OK ] in green and [ FAIL ] in red?
Well, check_status does exactly that. After each function is (silently)
completed, it checks the exit status and then prints a fancy little [OK] or
[FAIL] on the screen.

Now what happens when I define the exit status? I have a function at the
beginning of the script, going:

if [ $UID -eq 0 ]; then
echo "Don't run this script as root"
exit 1
fi

Q: how can I let check_status happen before it exits? So that it prints a
last [FAILED] on the screen?

Suggestions?

Niki Kovacs

PS: I'm running Slackware Linux 10.2

Re: One last command after "exit 1"?

am 15.02.2006 17:19:23 von cfajohnson

On 2006-02-15, Niki Kovacs wrote:
> Hi,
>
> I have a problem in a script that I can't seem to resolve. I'm writing a
> series of install scripts, and among other things, I have a fancy little
> function check_status... you've ever seen Gentoo's or Mandrake's boot
> scripts, with all those fancy little [ OK ] in green and [ FAIL ] in red?
> Well, check_status does exactly that. After each function is (silently)
> completed, it checks the exit status and then prints a fancy little [OK] or
> [FAIL] on the screen.
>
> Now what happens when I define the exit status? I have a function at the
> beginning of the script, going:
>
> if [ $UID -eq 0 ]; then
> echo "Don't run this script as root"
> exit 1
> fi
>
> Q: how can I let check_status happen before it exits? So that it prints a
> last [FAILED] on the screen?
>
> Suggestions?

Have you tried:

trap check_status EXIT

--
Chris F.A. Johnson, author |
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence

Re: One last command after "exit 1"?

am 15.02.2006 17:42:11 von joe

Niki Kovacs writes:

> I have a problem in a script that I can't seem to resolve. I'm
> writing a series of install scripts, and among other things, I have
> a fancy little function check_status... you've ever seen Gentoo's or
> Mandrake's boot scripts, with all those fancy little [ OK ] in green
> and [ FAIL ] in red? Well, check_status does exactly that. After
> each function is (silently) completed, it checks the exit status and
> then prints a fancy little [OK] or [FAIL] on the screen.
>
> Now what happens when I define the exit status? I have a function at
> the beginning of the script, going:
>
> if [ $UID -eq 0 ]; then
> echo "Don't run this script as root"
> exit 1
> fi
>
> Q: how can I let check_status happen before it exits? So that it
> prints a last [FAILED] on the screen?

Doesn't look like you have to check when you know what status you're
about to return.

I assume you have a function somewhere that prints the [OK] or [FAIL]
after checking, just call it before calling exit.

Joe
--
Gort, klatu barada nikto