Well, I didn't really understand what you were doing, but replacing:
Code:
LAST=`echo $THEUSER | awk '{ print $2; }'`
by:
Code:
LAST=`echo $THEUSER | awk '{ sub(/,$/, _, $2); print $2; }'`
should do what you want.
------
Some samples could help to make it
bash(1) only.
------
EDIT :
Never mind, I think I got it.
Code:
#!/bin/bash
user=$(getent passwd "$USER")
IFS=': ' read -r _ _ _ _ first last _ <<< "$user"
echo "$first.${last%%,*}@domain.com"
If you want it all lowercase:
Code:
#!/bin/bash
user=$(getent passwd "$USER")
IFS=': ' read -r _ _ _ _ first last _ <<< "$user"
last=${last%%,*}
echo "${first,,}.${last,,}@domain.com"