Your mail command must cause problems.
Change the mail command in your example to something fun like
yes more lines than you can count|head -6
and you'll see that bash evaluates both lines.
I haven't figured out how to set up mail on my system. The mailx man page says that -s sets the subject, and -i means "ignore keyboard interrupt". I presume your symptom is ``when I run the command the shell "just hangs"''.
Which likely means that mail patiently reads stdin to end of file. You'd enter the body of the message and end the file with C-d (^D) (control-d) .
If you already know the message body, change the input source and mail won't wait for you to type it.
Some ideas---
I'll bet you already have the message in a file! Then the command is (assuming -i is important which it probably isn't)
Code:
mail -i -s "noteworthy message" $( email_address $USER ) < message.body.txt
You'd precede the mail command with a program that customizes message.body.txt as appropriate. And you'd have to write or find the email_address program I just proposed.
If things are simpler, maybe you want to remind someone of the groups they belong to, the command would be
Code:
groups $USER | mail -s "Your groups on $( hostname )" $EMAIL
where $EMAIL expands to the correct email address. Good luck with that, I've never seen an EMAIL shell variable.