I'm trying to print out the users who are currently logged in (each logged in user of each terminal). This is what I currently have:
NOWDATE=$(date +"%Y-%m-%d")
NOWTIME=$(date +"%T")
USERS=$(who | awk -v nd="$NOWDATE"_"$NOWTIME" '{printf nd "\n" " User: "$1" Terminal: "$2" Login: "$3" "$4 "\n"}')
Unfortunately, \n
does not work, which means that I can't get a newline after the variable $4
. The output doesn't do any new lines. How can I achieve that printf
does a new line after the variable $4
?
Note: I just perform an echo to list the users, so echo $USERS