bashshellbash-trap

bash trap EXIT $LINENO always 1


test.sh

#!/bin/bash
set -e
trap 'echo $LINENO' EXIT
/bin/false

run

$ ./test.sh
1

How may I get the actual line number of "/bin/false" instead of always '1'?


Solution

  • You are getting 1 because you trap EXIT. Try :

    trap ... ERR