From owner-freebsd-questions Mon Nov 8 15:29: 4 1999 Delivered-To: freebsd-questions@freebsd.org Received: from scientia.demon.co.uk (scientia.demon.co.uk [212.228.14.13]) by hub.freebsd.org (Postfix) with ESMTP id 565461510A for ; Mon, 8 Nov 1999 15:28:37 -0800 (PST) (envelope-from ben@scientia.demon.co.uk) Received: from strontium.scientia.demon.co.uk ([192.168.0.4] ident=exim) by scientia.demon.co.uk with esmtp (Exim 3.092 #1) id 11kxxy-000KeP-00; Mon, 08 Nov 1999 23:12:50 +0000 Received: (from ben) by strontium.scientia.demon.co.uk (Exim 3.092 #1) id 11kxxx-0001EQ-00; Mon, 08 Nov 1999 23:12:49 +0000 Date: Mon, 8 Nov 1999 23:12:49 +0000 From: Ben Smithurst To: William Melanson Cc: slava revutchi , freebsd-questions@FreeBSD.ORG Subject: Re: shell's exit status variable Message-ID: <19991108231249.A3075@strontium.scientia.demon.co.uk> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG William Melanson wrote: > On Mon, 8 Nov 1999, slava revutchi wrote: > > % How do I check the shell's exit status variable? > > I know within the bash shell it would be as such: > >> [script]; echo $? > > The "$?" varaible prints the exit status of the last command run. > Either a "1" or "0". It can be a lot more than that. It can be any value from 0 to 255 inclusive, although as you say zero and one are probably the most common (since they correspond to the EXIT_SUCCESS and EXIT_FAILURE constants, respectively). Note that if $? is greater than 128, it *might* mean that the process was terminated by signal ($? - 128), e.g. ben@strontium:~/work/ifonline$ sleep 20 ^C ben@strontium:~/work/ifonline$ echo $? 130 130 - 128 = 2, which corresponds to SIGINT, delivered by me pressing ctrl-C. This 128+sig business is just a convention used by shells though and cannot really be relied on. -- Ben Smithurst | PGP: 0x99392F7D ben@scientia.demon.co.uk | key available from keyservers and | ben+pgp@scientia.demon.co.uk To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message