Home >Operation and Maintenance >Linux Operation and Maintenance >How to determine whether a user exists in Linux

How to determine whether a user exists in Linux

藏色散人
藏色散人Original
2021-12-14 10:52:2210723browse

Linux method to determine whether a user exists: 1. Save "read -p "please input a username:" username..." as test.sh; 2. Run "sh test.sh" .

How to determine whether a user exists in Linux

The operating environment of this article: linux5.9.8 system, Dell G3 computer.

How to determine whether a user exists in Linux?

linux Determine whether a user exists:

#!/bin/bash

read -p "please input a username:" username

if id -u $username >/dev/null 2>&1; then
        echo "user exists"
else
        echo "user does not exist"
fi

Save the above memory as test.sh, and then run sh test.sh

Recommended learning: "linux video tutorial"

The above is the detailed content of How to determine whether a user exists in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn