One of the things we wanted to do earlier is to automatically create usernames from the users first name and their surname.

For example, in the file to create users, I have a first name, a surname and the users primary group.

<FirstName> <Surname> <PrimaryGroup>

Hamish 			Whittal 	users

I would like to combine the surname and the first three letters of the firstname to create the users username - automatically!

We can use another of these parameter substitution constructs to achieve this:


where the OFFSET begins at 0 and LENGTH is the number of characters to keep in the total length of the user name.

Assuming I have read the above values into the variables:


As a result, we could use the following code to resolve our issue:

1.Chop the FIRSTNAME to the first 3 characters using our new construct:


which would leave us with:


2.Add the SURNAME to the shortened FIRSTNAME:


3.useradd -g ${PGROUP} -c "${FIRSTNAME} ${SURNAME}" -d /home/${USERNAME}


4.Now set up a script to make that work for every user listed in the userlist.txt file, use a loop construct to ensure that the entire file is read (the file to create users), and BINGO, you have just made your life easier!