Below is my simple bash script
!/usr/bin/sh
cmd_output=$(ctmcontb -ADD $2 $3)
echo below is the hex output of "CONDITION:${2} DATE:${3} added"
echo "CONDITION:${2} DATE:${3} added" | od -xc
echo below is the hex output for the variable cmd_ouput
echo "$cmd_output" | od -xc
echo raw input passed to cmdlet with user arguments inputted and a space added infront
echo " CONDITION:${2} DATE:${3} added" | od -xc
if [ "$cmd_ouput" = " CONDITION:${2} DATE:${3} added" ]; then
echo successfull ran util
exit 0
else
echo error occurred running util
exit 1
fi
Below is the output
ctmtest1-tctmsv80 [49] job_late.sh ctmtest1 u350932-14 0910
below is the hex output of CONDITION:u350932-14 DATE:0910 added
0000000 434f 4e44 4954 494f 4e3a 7533 3530 3933
C O N D I T I O N : u 3 5 0 9 3
0000020 322d 3134 2044 4154 453a 3039 3130 2061
2 - 1 4 D A T E : 0 9 1 0 a
0000040 6464 6564 0a00
d d e d \n
0000045
below is the hex output for the variable cmd_ouput
0000000 2043 4f4e 4449 5449 4f4e 3a75 3335 3039
C O N D I T I O N : u 3 5 0 9
0000020 3332 2d31 3420 4441 5445 3a30 3931 3020
3 2 - 1 4 D A T E : 0 9 1 0
0000040 6164 6465 640a
a d d e d \n
0000046
raw input passed to cmdlet with user arguments in putted and a space added in front
0000000 2043 4f4e 4449 5449 4f4e 3a75 3335 3039
C O N D I T I O N : u 3 5 0 9
0000020 3332 2d31 3420 4441 5445 3a30 3931 3020
3 2 - 1 4 D A T E : 0 9 1 0
0000040 6164 6465 640a
a d d e d \n
0000046
error occurred running util
So as you can see the string comparison line
if [ "$cmd_ouput" = " CONDITION:${2} DATE:${3} added" ]; then
doesn't appear to successfully compare the strings even though they are from what I can see the same.
I noticed there was a space added to the raw input after it is run through the cmdlet. So to combat this I basically added a space manually in the string comparison (I know not the greatest way of doing it but I ran out of ideas)
Basically im not sure why the string comparison is not working when the strings are the same and my bash code appears correct?
bash -x job_late.sh ctmtest1 u350932-14 0910as well? I notice that your shebang line lacks a#. Other than that, nothing obvious.ctmcontbreturn a return code which indicates if it was successful or not. You can get the return code of the last executed command in bash using"$?"and then case out on this integer, it's a pretty useful trick.