help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Something like die from perl in bash?


From: Greg Wooledge
Subject: Re: [Help-bash] Something like die from perl in bash?
Date: Tue, 28 Jan 2014 10:45:20 -0500
User-agent: Mutt/1.4.2.3i

On Tue, Jan 28, 2014 at 09:40:29AM -0600, Peng Yu wrote:
> Hi,
> 
> "die" in perl can print an error message as well as set the return
> code of the perl script. I frequently need to print an error message
> and exit with the last error code. I'd like to make it one line. Is it
> possible in bash?
> 
> prog_to_fail || exit $? # how to print an error message as well exit
> with the last status code?

die() {
    local status=$?
    echo "$1" >&2
    exit $status
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]