Automation, Orchestration, and Scripting

An administrator must print each account name and its login shell from /etc/passwd, where fields are separated by colons and the shell is the seventh field. Which loop reads the file correctly?

Show the answer

Correct answerB. while IFS=: read -r user _ _ _ _ _ shell; do echo "$user $shell"; done < /etc/passwd

Setting IFS to a colon for the read command splits each line on colons, so the seventh variable receives the shell. FS is an awk variable, so bash ignores it and read still splits on whitespace, leaving the whole line in the first variable.