#!/bin/bash
OLDIFS=$IFS
IFS=","
while read firstname lastname userid
do
sudo useradd -c "${firstname}.${lastname}" -d /home/students/student/"${firstname}.${lastname}" -G students -s /bin/bash "${userid}"
done < hello.csv
Run Code Online (Sandbox Code Playgroud)
从联机帮助页:
Run Code Online (Sandbox Code Playgroud)-m, --create-home Create the user's home directory if it does not exist. The files and directories contained in the skeleton directory (which can be defined with the -k option) will be copied to the home directory. By default, if this option is not specified and CREATE_HOME is not enabled, no home directories are created.
但是,我强烈建议不要像使用-d /home/students/student/"${firstname}.${lastname}". 想想像“John A. Doe”这样的(真实的)用户名。他的 $HOME 目录将包含一个空格,这对用户来说并不完全友好。
| 归档时间: |
|
| 查看次数: |
545 次 |
| 最近记录: |