As colucix pointed out, your main problem is in your test statement. You have to put spaces around the test brackets. This is because '[' is actually a command name. It's an alias for 'test'. The ending bracket is not strictly necessary, but all modern bash versions require it.
But let's give you a few other formatting tips also.
1) The double quotes (") are considered the "weak" quoting mechanism, because variable expansion and some other translations will still work inside them. This means you can do, for example:
Code:
echo "Comparing $file -- $changeFlag"
instead of
echo Comparing $file "--" $changeFlag
(You should always quote all of your echo outputs in any case.)
Single quotes, OTOH, (') are "hard" quotes, because everything inside them will be taken literally.
2) The backtick (`) form of command substitution has been superseded by the '$()' form. Not only is it easier to read, but they can more easily be nested.
Code:
wfName=`echo $wf_twist_dir | sed 's/.*\/\(.*$\)/\1/'`
should more properly be
wfName="$(echo $wf_twist_dir | sed 's/.*\/\(.*$\)/\1/')"
3) Speaking of the above string, there are better ways to get the base name of a file than using sed. One is to use the 'basename' command. Another is to use
parameter substitution.
Finally, even the sed command can be cleaned up if you use some other character as the separator instead of '/', and add the -r (extended regex) flag, so you don't have to escape everything.
Code:
wfName="$(basename $wf_twist_dir)"
or
wfName="${wf_twist_dir##*/}"
or
wfName="$(echo $wf_twist_dir | sed -r 's|.*/(.*$)|\1|')"
4) '$variable' is only used when you want to output the value of a variable. Use the variable name without the dollar sign when you want to set it. You made this mistake inside the if statement. Also, '${variable}' is the extended form of '$variable', which will let you more safely combine them inside of character strings, as well as performing various parameter substitutions.
You should generally quote the variable values when you set them (variable="value"), except perhaps when it's a simple integer or such.
Code:
changesExist=1
emailBody1="${emailBody1}Workflow Name: $wfName\nTool Name: $toolName\nChanges:\n"
emailBody1="${emailBody1}$(diff -y $wf_twist_dir/$file $wf_nas_dir/$file --suppress-common-lines)\n\n"
Edit: one more:
5)
Your final echo statement will not be formatted correctly. You need to use 'echo -e' for it to translate the newline characters in the variable output. Also the variable should be quoted so that the contents are seen as a single unit.
Code:
echo -e "$emailBody1"