C'est quoi, whoami ?
whoami affiche simplement le nom de l'utilisateur courant. Surtout utile dans les scripts pour vérifier sous quel compte on tourne.
💡 La question existentielle du terminal. Souvent la première commande qu'on tape après un su ou sudo pour vérifier qui on est devenu.
$ whoami
ubuntu
$ sudo su
root@server# whoami
root
# Dans un script bash
USER=$(whoami)
echo "Script lancé par : $USER"
# Vérifier si on est root
if [ "$(whoami)" != "root" ]; then
echo "Ce script doit être lancé en root"
exit 1
fi