X-Spam-Check-By: sourceware.org Message-ID: <468204ED.2040603@linux.vnet.ibm.com> Date: Tue, 26 Jun 2007 23:34:21 -0700 From: Richard A Nelson User-Agent: Mozilla-Thunderbird 2.0.0.4 (X11/20070622) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: Bash is broken wrt trap :( References: <4681CDCD DOT 7030709 AT linux DOT vnet DOT ibm DOT com> In-Reply-To: Content-Type: multipart/mixed; boundary="------------000808060705060000060106" Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com --------------000808060705060000060106 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Igor Peshansky wrote: >> >> I have code that must run on AIX (bash/ksh93), Linux (bash/ksh93), and >> Cygwin (bash - pdksh is not sufficient and I couldn't find ksh93)... > > What's missing in pdksh? subscript references, for one (ie ${OS:0:6}), which is fairly common in the scripts (though, most all could be replaced with ${OS%...} or ${OS#...} ) Also, I could find no way to have pdksh propagate the errors all the way up the call chain. The scripts have sourced common routines, and may also be called from other scripts (so I have a combination of local, shared functions in the same process, and subprocesses used to invoke a subshell/script). An example of the structuring might be helpful; I have separate scripts that build each component of our product (compiler, runtime, sort, ICU, etc...). The scripts may be run stand-alone, or from a higher level 'build-it-all' script. Then, there are several common subroutine script files that are source in each and every build/test script to handle things like cron job scheduling, command line parsing, etc. >> if [ -n "$BASH" -a "${OS:0:6}" != 'CYGWIN' ]; then > > This won't work -- OS is a variable set by Windows. On my WinXP, I get > OS=Windows_NT, so ${OS:0:6} is 'Window'. Eh? in Cygwin? Works just fine here, $OS is not marked readonly - tho the subscript fails on pdksh :( > You want something like "$(uname -s | cut -c 1-6)" instead, or use > "$(uname -o)". uname -o doesn't carry across non-GNU toolchains (AIX) :( but this was just an example usage >> UNWIND="trap 'false' RETURN;return 1"; > > I'm not sure this does what you expect it to. It seems like this sets the > RETURN trap *in the child*, which is executed, again in the child, as soon > as you return. It is documented that the RETURN trap executes in the context of the parent, after the completion of the child (though, in the case of sourced, or in file functions, there should be no parent/child process) > And what is the output you expect from the above script? That every error > handler up the call chain is triggered? Exactly... $ ./sample OS=Linux bash=3.00.15(1)-release braceexpand on hashall on interactive-comments on posix on >>main >>do_a >>do_b ./sample/do_b: *** ERROR *** ERROR *** ERROR *** <>do_a'; do_b; echo '<>do_b'; false; echo '<>main' do_a; echo "<