EX200 • Practice Test 11
Free EX200 practice test — 15 questions with explanations. Set 11. No signup required.
You are tasked with creating a script that reads a list of usernames from /tmp/users.txt, one per line, and creates a home directory for each user using `mkdir /home/$username`. The script is:
#!/bin/bash
while read username; domkdir /home/$username done < /tmp/users.txt
However, the script fails for usernames that contain spaces (e.g., 'john smith'). The error is 'mkdir: cannot create directory '/home/john': File exists' and then a separate directory for 'smith'. What is the best fix?