Error Code Generated by Script

Hi,

I have written a script with several variables derived from here documents. However, when I run the following code, the exit status becomes 1:

BMC_ACEs="Rich"

read -r -d '' BMC_ACL <<EOF
###
### ACL Rack01-BMCMgmt_IN
###
$BMC_ACEs
EOF

If I then type echo $?, it displays a 1. I need my code to return 0 unless there is a real error. I have error-handling code elsewhere in the script that catches the error and echoes it to the user:

# Error handling
failure()
{
  local lineno=$1
  local msg=$2
  echo "Line $lineno: $msg"
}

trap 'failure ${LINENO} "$BASH_COMMAND"' ERR

Is there a mistake in my code or is there a workaround to get it to return 0?

Thanks,

Rich

man bash :

By setting -d'' , i.e. the delimiter to the "empty string", read will not stop anywhere but read through to the EOF string which it interprets as end-of-file and sets $? to 1.

Thanks for the reply. Is there a way for me to accomplish the task without generating that return code? I need to put a multi-line string with variable interpolation into a variable.

Use a different delimiter, e.g. a character that definitely won't occur in your text. Good candidates are ASCII control characters. Why not a "carriage return" (<CR> = \r = ^M = 0x0D) which is of inferior significance in *nix texts. Like

$ CR=$'\r'
$ read -r -d$CR  BMC_ACL <<EOF
###
### ACL Rack01-BMCMgmt_IN
###
$BMC_ACEs
$CR
EOF
$ echo $?
0
$ echo "$BMC_ACL"
###
### ACL Rack01-BMCMgmt_IN
###
Rich

That fixed it. Thanks!