我要问用户名和打印与该用户名相关的名称和主目录路径打印使用用户名
echo Please enter your username
read username
我不知道如何使用$用户名相关的名称和主目录路径找到有关其主目录和名称的信息。
我要问用户名和打印与该用户名相关的名称和主目录路径打印使用用户名
echo Please enter your username
read username
我不知道如何使用$用户名相关的名称和主目录路径找到有关其主目录和名称的信息。
echo Please enter a username
read username
cat /etc/passwd | grep "$username" | cut -d ":" -f6
cat /etc/passwd | grep "$username" | cut -d ":" -f5
awk -F: -v v="$username" '{if ($1==v) print $6}' /etc/passwd
没有AWK:
cat /etc/passwd | grep "$username" | cut -d ":" -f6
用户名:
cat /etc/passwd | grep "$username" | cut -d ":" -f5
OP也想要名字。 –
对不起,但我不知道这个缩写。 OP? –
原始海报。这个人提出了这个问题。 –
使用getent
read -p "username: " username
IFS=: read username password uid gid gecos homedir shell < <(getent passwd "$username")
echo "fullname=${gecos%%,*}"
echo "homedir=$homedir"
如果夏娃把她的名字命名为爱丽丝,该怎么办? –