シェルスクリプト

ログイン中ユーザーの判定

#!/bin/sh

if [ "`whoami`" = "root" ]; then
        echo "あんたはエラい!"
else
        echo "フーン"
fi

ユーザーが存在するかしないか判定する

 #!/bin/sh
 
 if [ "`getent passwd $1`" = "" ]; then
         echo "$1: Not exists."
 else
         echo "$1: Already exists."
 fi
最終更新:2022年04月13日 10:09