答案1
修复你的“导出历史时间格式” 线为
export HISTTIMEFORMAT="%F %T %t"
- 等号=后不能有空格
- 使用双引号 " 而不是反引号 `
编辑以回答有关 user_full_name 的问题。
我们没有用户全名默认情况下是变量,但我们可以创建它。
#!/bin/bash
#
# taking first part (up to a first comma symbol)
# from "Full name of the user (GECOS)" field of /etc/passwd file
# and removing double quote symbols from it
user_full_name=$(/bin/getent passwd $USER |cut -d: -f5|cut -d, -f1|sed 's/"//g')
# if that field is empty, using username as full name
[ -z "$user_full_name" ] && user_full_name=$USER
export user_full_name
#
echo "Hello $USER, Your UID is $UID , Your full name is $user_full_name "
export HISTTIMEFORMAT="%F %T %t"
history 5