#!/bin/sh -u # $0 (no arguments) # Purpose: Display the full user@domain email address of the user. # # BUGS: Does not work unless there is a "domain" line in /etc/resolv.conf # # WARNING: Many of the comments in this file are "Instructor-Type" # comments and are *not* appropriate for real scripts. Do not put # "Instructor-Type" comments into the scripts that you submit for marking. # I put them in my example files because I am teaching you how to # write scripts; do not submit my teaching comments back to me again. # -IAN! idallen@ncf.ca # Set the search path for the shell to be the standard places. # Set the umask to be non-restrictive and friendly to others. # - nothing in this script now actually creates any files, so the umask # will not be needed; but, keep it here in case of future changes # export PATH=/bin:/usr/bin umask 022 # Set variables to be each part of the email address. # - variable assignment is optional; it makes the code clearer # Use shell "Command Substitution" to get the needed information. # - no need to quote here: wildcards do NOT expand in assignment statements # The leading '^' in the pattern means "only at the beginning of the line". # - I quote the '^' character if I don't know how the shell might interpret it # The awk code prints the second field in all lines coming from stdin. # - it works both for blank-delimted and/or tab-delimited fields # - the single argument to awk must be fully protected from the shell # whoami=$(whoami) domain=$(grep -e '^domain' /etc/resolv.conf | awk '{print $2}') # Quote the variables to prevent any possible glob/wildcard expansion. # Note the difference between $whoami [a variable] and $(whoami) [a command]. # I quote the '@' character if I don't know how the shell might interpret it. # echo "$whoami@$domain"