Shell script for creating multiple users with password

for UserName in `cat users` ; do useradd -d /u02 -s /usr/libexec/openssh/sftp-server -G ftp-users $UserName ; 
PassWord=$( echo $( tr '[:lower:]' '[:upper:]' <<< ${UserName:0:1} )${UserName:1} ) ; 
echo "$PassWord@123" | passwd $UserName --stdin ; done

can some one explain what the bold text do

It sets the variable "PassWord" to the first char of "UserName" tr anslated to upper case followed by the rest of "UserName" in whatever case it may be.

echo $( tr '[:lower:]' '[:upper:]' <<< ${UserName:0:1} )${UserName:1}

i'm little concerned about "<<<" redirection and :0:1 :1 over there

Those are

  • Here Strings
  • Parameter Substring Expansion

both described in your shell's man page.

The <<< redirection operator and the ${var:start:count} and ${var:start} substring parameter expansions are extensions to the standards that are provided by some, but not all, shells.

The <<< "string" redirection operator feeds the string string followed by a <newline> character to the standard input of the command it follows.

The substring parameter expansion ${var:start[:count]} expands to the count characters (all characters if :count is not specified) starting with the character at the position specified by start (where 0 is the first character in the expansion ${var}) . So, ${UserName:0:1} gives you the 1st character of $UserName and ${UserName:1} gives you the remaining characters in $UserName .

The the tr '[:lower:]' '[:upper:]' translates lowercase characters read from standard input to the corresponding uppercase letters on standard output. Characters read from standard input that are not lowercase letters are copied to standard output unchanged.

The outer command substitution using echo to print the output from the inner command substitution and substring parameter expansion is not needed. It could be more succinctly written as:

PassWord=$( tr '[:lower:]' '[:upper:]' <<< ${UserName:0:1} )${UserName:1}

to assign the variable PassWord the user's login name with the 1st character translated to an uppercase character if it started with a lowercase letter; or to the user's login name (unchanged) if it did not start with a lowercase letter.

That was really help, and nice explanation