我要問用戶名和打印與該用戶名相關的名稱和主目錄路徑打印使用用戶名
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"
如果夏娃把她的名字命名爲愛麗絲,該怎麼辦? –