Code:
freebsd-version
12.3-RELEASE-p5
I have a bash script with a function that contains the following code:
Code:
. . .
OPT_t=0
. . .
t)
let "OPT_t+=1"
;;
. . .
f_msg_attach()
{
local _passed_msg_file _passed_attach_file _passed_content_type
_passed_msg_file="$1"
_passed_attach_file="$2"
_passed_content_type="$3"
[ "$OPT_t" -gt 1 ] && echo "Processing: $_passed_attach_file Content-Type: ${_passed_content_type}"
local _content_block _file_name
_file_name="$(basename "${_passed_attach_file}")"
# Second line indent indicates continuation from preceding line
_content_block=$(cat << CBLK
--${MIME_MP_BOUNDARY}
Content-Type: ${_passed_content_type};
name="${_file_name}"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="${_file_name}"
CBLK
)
echo "${_content_block}" >> "${_passed_msg_file}"
echo -e "" >> "${_passed_msg_file}"
base64 -e "${_passed_attach_file}" >> "${_passed_msg_file}"
[ "$OPT_t" -gt 1 ] && ls -l "${_passed_msg_file}"
}
When the script is run, with or without a
-t
option, the script halts at this line:
Code:
Line 235: echo -e ''
Line 236: base64 -e /usr/local/www/apache24/data/hll_DaV/upload/eBillings/IN356000-IN356999/IN356753/HLL_Employee_Timesheet.ots
Line 238: '[' 0 -gt 1 ']'
If the line is commented out then the script runs as expected. Note that the same idiom is used earlier in the function and the script does not fail at that point.
What is wrong with this code?
A. When OPT_t is 1 or less then the function returns false which stops the script. Adding a no-op or any other instruction that succeeds after the test prevents the problem arising when the test fails. So:
[ "$OPT_t" -gt 1 ] && ls -l "${_passed_msg_file}" || :