Considering the following shellscript:
#!/bin/bash
echo test > /usr/lib/permDenied 2>&1 > /dev/null
echo $?
This gives me the following error:
$ ./test.sh
./test.sh: line 2: /usr/lib/permDenied: Permission denied
1
How can I make the error silent and get the error code as well?