【发布时间】:2012-06-21 14:52:36
【问题描述】:
我想创建一个 Bash 脚本来检查 /etc/passwd 中是否存在用户名。如果存在则将其添加到users.txt 文件中。
我不太擅长 UNIX 编程,所以希望有人能帮助我。
while(get to the end of /etc/passwd){
name=$(cat /etc/passwd | cut -d: -f1);
num1=$(cat /etc/passwd | cut -d: -f3);
num2=$(cat /etc/passwd | cut -d: -f4);
if(num1==num2)
/*i compare argv[0] with $name */
/* if true i=1 */
}
if(i==1)
save following string "argv[0]=agrv[1]"
else
"error message"
【问题讨论】: