john iLoveMary mary iHateJohn jason mmmmmm maggie iAmLonely
第一位为 username,
第二位为 password,两个栏位位间以一或多個空白隔開。
Script 的內容如下:
#!/bin/bash echo -n " Give me the name of the file containing user data..." read file [ ! -f $file ] && ( echo " '$file' does not exist..."; exit 1 ) while read username password do useradd $username >/dev/null 2>&1 if [ $? -ne 0 ] then echo " Fail to create an account with name=$username..." else echo $password | passwd --stdin $username >/dev/null 2>&1 [ $? -ne 0 ] && echo " Fail to set password for '$username'..." fi done < $file