【发布时间】:2013-12-21 17:00:48
【问题描述】:
#!/bin/bash
initial="/"
usrname=`cut -d ":" -f1 users.txt`
password=`cut -d '"' -f3 users.txt|cut -d ":" -f2`
comment=`cut -d '"' -f2,3 users.txt|cut -d ":" -f1`
path=`cut -d "/" -f2,3 users.txt`
totalpath="$initial$path"
while read line
do
useradd -p "$password" -c "$comment" -m -d "$totalpath" "$usrname"
done < "users.txt"
我正在尝试使用文本文件添加多个用户。我收到“意外标记‘完成’附近的语法错误”。 我所有存储的变量都非常完美。我使用 echo 命令对其进行了测试。但是,当我运行循环时,会弹出错误消息并且没有创建用户。
供您参考,这是我的文本文件的样子:
acdeng:"ADLER CHARLES DAVID",00-9388,x0753,Engineering:acc944:/home/Engineering
ardsal:"ANSELL ROBERT D",14-2675,x1624,Sales:acc944:/home/Sales
【问题讨论】:
-
除了任何语法错误外,
$password、$comment等的值不会每次通过while循环更新;只有$line被更新,你不使用它的值。 -
您是否复制并粘贴了您的准确代码?我不相信您发布的代码中存在语法错误(尽管存在一些严重的逻辑错误)。
-
我是脚本新手。是的,我复制了确切的代码。
标签: linux bash shell while-loop