Quantcast
Channel: my tech blog » Linux
Viewing all articles
Browse latest Browse all 173

A function similar to Perl’s die() in bash

$
0
0

This is maybe a bit silly, but Perl has a die() function that is really handy for quitting a script with an error message. And I kind of miss it in Bash. So it can be defined with this simple one-liner:

function die { echo $1 ; exit 1 ; }

And then it can be used with something like:

unzip thefile.zip || die "Unzip returned with error status"

The Perl feeling, in Bash.


Viewing all articles
Browse latest Browse all 173

Latest Images

Trending Articles



Latest Images