Skip to content

Instantly share code, notes, and snippets.

@dermoth
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dermoth/9337183 to your computer and use it in GitHub Desktop.
Save dermoth/9337183 to your computer and use it in GitHub Desktop.
Bash (()) and error handling
[thomas_guyot@localhost ~]$ bash --version
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
[thomas_guyot@localhost ~]$ trap 'echo Argh' ERR
[thomas_guyot@localhost ~]$ variable=0
[thomas_guyot@localhost ~]$ ((variable++))
[thomas_guyot@localhost ~]$ echo $?
1
[thomas_guyot@localhost ~]$ echo $variable
1
[root@localhost ~]# bash --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
[root@localhost ~]# trap 'echo Argh' ERR
[root@localhost ~]# variable=0
[root@localhost ~]# ((variable++))
Argh
[root@localhost ~]# echo $?
1
[root@localhost ~]# echo $variable
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment