結(jié)果卻是一直報錯
./add_ftpuser.sh
./add_ftpuser.sh: line 5: UID: readonly variable
useradd: UID 0 is not unique
passwd: Unknown user name 'user1'.
./add_ftpuser.sh: line 5: UID: readonly variable
useradd: UID 0 is not unique
passwd: Unknown user name 'user2'.
./add_ftpuser.sh: line 5: UID: readonly variable
useradd: UID 0 is not unique
passwd: Unknown user name 'user3'.
奇怪的是,UID和GID都是數(shù)字,但是一個報錯,一個正常,用bash -x 方式執(zhí)行,可以看到gid都被正常賦值
+ read USER UID GID DIR SH PASSWD
add_ftpuser.sh: line 5: UID: readonly variable
+ useradd -m -d /ftp/user1 -u 0 -g 100 -s /bin/bash user1
useradd: UID 0 is not unique
看abs, bash internal variables http://tldp.org/LDP/abs/html/internalvariables.html
This is the current user's real id, even if she has temporarily assumed another identity through su. $UID is a readonly variable, not subject to change from the command line or within a script,