A system administrator is writing a shell script that reads usernames from a file named users.txt and needs to verify whether each account exists on the local system. Which command is the most suitable to place inside the loop to test if a specified user account is present?
The id command outputs user and group identity details for the supplied username. When the named user exists, id returns the relevant information and an exit status of 0; if the user does not exist, it produces an error and a non-zero exit status, allowing the script to branch accordingly.
pwd only prints the current working directory, whoami shows the effective user running the script (and accepts no username argument), and hostname displays the machine's host name-none of which can check another user's existence.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the 'id' command do beyond checking user existence?
Open an interactive chat with Bash
Can you explain what a shell script is and how it works?
Open an interactive chat with Bash
What are the differences between 'id', 'whoami', and 'pwd' commands?