I observe this behavior under OpenSSL 1.0.0e on Ubuntu 11.10, whereas OpenSSL 0.9.8k and 0.9.8t output just the hash. OpenSSL's command line is not designed to be flexible, it's more of a quick-and-dirty way to perform cryptographic calculations from the command line.
If you want to use OpenSSL, filter the output:
echo -n "foo" | openssl dgst -sha1 | sed 's/^.* //'
On Linux (with GNU tools or BusyBox), you can use sha1sum, which doesn't require OpenSSL to be installed and has a stable output format. It always prints a file name, so strip that off.
echo -n "foo" | sha1sum | sed 's/ .*//'
On BSD systems including OSX, you can use sha1.
echo -n "foo" | sha1 -q
All of these output the checksum in hexadecimal followed by a newline. Text under unix systems always consists of a sequence of lines, and each line ends with a newline character. If you store the output of the command in a shell variable, the final newline is stripped off.
digest=$(echo -n "foo" | openssl dgst -sha1 | sed 's/^.* //')
If you need to pipe the input into a program that requires a checksum with no final newline (which is really rare), strip off the newline.
echo -n "foo" | openssl dgst -sha1 | sed 's/^.* //' | tr -d '\n' | unusual_program