📄 adduser.sh
字号:
#!/bin/sh# Purpose: To write a script to add user to the system.# Name: adduser.sh# Check for only a single command line argumentif [ $# -ne 1 ] then echo "Usage: adduser newusername" exit 1fi# Assign the value of $1 to the variable namename=$1if grep "^$name:" ./mypasswd > /dev/null 2>&1then echo "The username $1 is already in use, here " echo "is the entry from the ,/mypasswd file." echo grep "^$name:" ./mypasswd exit 2fi# Use nawk to extract all the UIDs into the temp file currentuidnawk -F: '{print $3}' ./mypasswd > ./currentuid# Use sed to remove all 1, 2, and 3 digit UIDs from currentuid, and# place the output in the temp file currentuid2sed -e '/^.$/d' -e '/^..$/d' -e '/^...$/d' ./currentuid > ./currentuid2# Use sed to remove UIDs 60001, 60002, and 65534 from currentuid2,# and place the output in the temp file currentuid3sed -e '/^6000[12]$/d' -e '/^65534$/d' ./currentuid2 > ./currentuid3# Sort the UIDs in currentuid3 numericallysort -n ./currentuid3 > ./currentuid4# Calculate the next available UIDlastuid=`sed -n '$p' ./currentuid4`uid=`expr $lastuid + 1`echo "The uid for $name is: $uid"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -