A system administrator has been tasked with writing a shell script that reads a list of usernames from a text file named 'users.txt' and then checks whether each user exists on the system. The admin decides to use a loop along with a built-in command to verify this. Which command should be used within the loop to check the presence of a user account in the system environment?
The 'id' command is used to obtain user and group identity information, which makes it an appropriate tool for checking whether a user account exists. Specifically, the id command returns the user and group information for the specified username, and if the user does not exist, it will produce an error message. The other commands listed do not serve the purpose of checking for the existence of a user account. For instance, 'pwd' displays the current directory, 'whoami' shows the current user, 'date' outputs the current date and time, and 'hostname' reveals the system's host name.
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?