From owner-freebsd-questions@FreeBSD.ORG Tue Dec 27 20:25:23 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2AF98106566B for ; Tue, 27 Dec 2011 20:25:23 +0000 (UTC) (envelope-from max@mxcrypt.com) Received: from mail-vw0-f54.google.com (mail-vw0-f54.google.com [209.85.212.54]) by mx1.freebsd.org (Postfix) with ESMTP id E1BBE8FC15 for ; Tue, 27 Dec 2011 20:25:22 +0000 (UTC) Received: by vbbfr13 with SMTP id fr13so16370143vbb.13 for ; Tue, 27 Dec 2011 12:25:22 -0800 (PST) Received: by 10.52.21.83 with SMTP id t19mr13903087vde.71.1325017522281; Tue, 27 Dec 2011 12:25:22 -0800 (PST) MIME-Version: 1.0 Received: by 10.220.150.132 with HTTP; Tue, 27 Dec 2011 12:24:51 -0800 (PST) From: Maxim Khitrov Date: Tue, 27 Dec 2011 15:24:51 -0500 Message-ID: To: FreeBSD Content-Type: text/plain; charset=UTF-8 Subject: Unexpected sh behavior with EXIT trap and errexit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Dec 2011 20:25:23 -0000 Can anyone explain this behavior (FreeBSD 9.0-RC3 amd64): Script: ---- #!/bin/sh cleanup() { echo 'first' echo 'second' } fail() { return 42; } trap cleanup EXIT set -o errexit fail ---- Output: ---- first ---- Now comment out 'set -o errexit', replace 'fail' with 'fail || exit' (which should be equivalent to using errexit), and run again. Output: ---- first second ---- Am I doing something stupid or is this a bug? Bash prints out the same (second) output for both versions of the code. - Max