Canonical environment variable representing a user's email address
If you really want to do that ("expect the users of my script to need to specify the address they want to use"), you can always ask them to put their email-address into ~/.emailaddress
or another local file. With adequate permissions on their home directories and that file, this could work.
The proper way would be to set up local mail delivery and leave it to the users if they want to use local mailing or their "external" address using ~/.forward
.
In my opinion, any sensible approach would store the "external" email address in a file, rather than an environment variable. There is a lot that can happen that prevents the environment variable from being set/available within your script. As root you can enforce the file being readable, but you cannot enforce the user being clever about where and how they put their envvar definitions.
There is not "the best way" of doing that. Email addresses are user information and therefore belong with your user management. If you use LDAP, dawud's answer tells you where to put and retrieve it. If you are using plain old /etc/passwd
, that one has a comment-field. If you want to store it in their home-directories (and that's what you do when you talk about users providing that information in their shell environments) I gave you two ways to accomplish that, depending on whether you have/want local mail.
If you're already using LDAP, going with dawud's advice is the best way for you. If you are not, setting up LDAP just to store some email-addresses is overkill and not the best way. If you want a definitive answer, you need to be a lot more specific about your question.