如何制作现有用户的主目录?

vis*_*ati 2 bash

#!/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)

Per*_*uck 5

联机帮助页

-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.
Run Code Online (Sandbox Code Playgroud)

但是,我强烈建议不要像使用-d /home/students/student/"${firstname}.${lastname}". 想想像“John A. Doe”这样的(真实的)用户名。他的 $HOME 目录将包含一个空格,这对用户来说并不完全友好。