How to trap exit code in Bash script

The accepted answer is basically correct, I just want to clarify things. The following example works well: #!/bin/bash cleanup() { rv=$? rm -rf “$tmpdir” exit $rv } tmpdir=”$(mktemp)” trap “cleanup” EXIT # Do things… But you have to be more careful if doing cleanup inline, without a function. For example this won’t work: trap “rv=$?; … Read more

Multiple Bash traps for the same signal

Technically you can’t set multiple traps for the same signal, but you can add to an existing trap: Fetch the existing trap code using trap -p Add your command, separated by a semicolon or newline Set the trap to the result of #2 Here is a bash function that does the above: # note: printf … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)