Question: My bash code look likes:

```
  set -e
  (
     flock -n 9
     main $@
   ) 9>/var/lock/mylockfile

```

But currently it don't show any error message, if it is not able to get lock on the file. 
Is there a way to show error message ?

Answer: 
With "set -e", you can use the ERR signal. As said in the man page of bash
(description of the "set" command with option "-e"): 

```
"A trap on ERR, if set, is executed before the shell exits."

```

So you can try something like:

```
set -e
(
  trap 'echo flock failed.' ERR
  flock -n 9
  trap - ERR   # reset ERR trap
  main $@
) 9>/var/lock/mylockfile

```
You should check for the return code of `flock -n`

```
 set -e
  (
     flock -n 9
     if [ "$?" -eq 1 ] ; then 
        echo "could not lock"
        exit 1
     fi
     main $@
   ) 9>/var/lock/mylockfile

```