Use a expansão de parâmetros:
#! /bin/bash
strings=('Job with id 0 ended with status COMPLETED, return code 16, in 1 minute 12 seconds'
'Job with id 0 COMPLETED with return code 255'
)
for string in "${strings[@]}" ; do
code=${string#*return code }
code=${code%%[!0-9]*}
echo $code
done
#
remove o padrão da esquerda, %
da direita.