Я переделал код на что-то менее сложное, и теперь он говорит:
ubuntu@ubuntu-VirtualBox:~$ ./newuseradd.sh Newbies.csv [sudo] пароль для ubuntu: useradd: группа «acct» не существует useradd: группа 'hr' не существует useradd: группа "покупка" не существует
Скрипт:
#!/bin/bash
if [ $# -ne 1 ]; then
echo "USAGE: $0 FILE"
exit 7
fi
sed -i'.bak' 's/Accounting/acct/;s/Purchasing/purch/;s/Human Resources/hr/;s/Information Technology/it/' $1 # Part 3 - transforming the group names
while read line; do
userinfo=($(echo $line | tr ',' ' '))
firstinitial=$(echo "${userinfo[1]}" | cut -c1)
username=$(echo ${firstinitial}${userinfo[0]} | tr A-Z a-z)
echo useradd $username -g ${userinfo[2]} -G employee -c ${userinfo[3]} -m #Part 2
echo "$(date): $username, ${userinfo[1]}, ${userinfo[0]}, $?" >> it-log.txt #Part 4 assigment- it log
echo -n "${userinfo[0]}, ${userinfo[1]}" >> hr-log.txt
grep "$username" /etc/passwd | cut -d':' -f1,7,3 | tr ':' ',' >> hr-log.txt
done < $1 #part 1 assigment