a) The output of command1 can be catched with
output=$(diff "helloworld$x.out" "output/helloworld$x.out")
or with backticks, but those are discouraged, because you can't nest them, and they might be hard to distinguish from apostrophs, depending on the font:
output=`cmd1`
b) Instead of writing to a file, and then reading that file, (or grabbing the output, and then echoing it) you would use a pipe directly:
cmd1 > file
cat file | cmd2
output=$(cmd1)
echo "${output}" | cmd2
=>
cmd1 | cmd2
but in your example, you're not interested in the output, but the outcome of the program - did it work?
diff "helloworld$x.out" "output/helloworld$x.out" && echo "success" || echo "failure"
To read about the use of && and || search for "shortcut AND and shortcut OR".
To keep the output clean, you can redirect the output of 'diff' to nowhere:
diff "helloworld$x.out" "output/helloworld$x.out" >/dev/null && echo "success" || echo "failure"
To grab success and evaluate it later, you store the result of the last command in a variable with $?:
diff "helloworld$x.out" "output/helloworld$x.out" >/dev/null
result=$?
# do something else
case $result in
0) echo success ;;
*) echo failure ;;
esac