EX200 Create simple shell scripts • Complete Question Bank
Complete EX200 Create simple shell scripts question bank — all 0 questions with answers and detailed explanations.
Drag steps to the numbered slots on the right, or tap a step then tap a slot.
Drag a concept onto its matching description — or click a concept then click the description.
Install a package with dependencies
Uninstall a package
Update all packages to latest versions
Show all installed packages
Refer to the exhibit. ```bash #!/bin/bash # Script to count lines in files for file in *.txt; do wc -l "$file" done ```
Refer to the exhibit. ```bash #!/bin/bash # Script to test a condition if [[ $? -eq 0 ]]; then echo 'Success' fi ```
Refer to the exhibit. ```bash #!/bin/bash # Script to set environment variable MY_VAR="hello" export MY_VAR ```
Refer to the exhibit. #!/bin/bash if [ $var = "value" ] then echo "Match" fi Error: [: =: unary operator expected
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; do
mkdir /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?
You maintain a script that performs a long-running task and must clean up temporary files if the script is interrupted. The script uses:
#!/bin/bash tempfile=$(mktemp) trap "rm -f $tempfile" EXIT
# long task
sleep 100
You notice that if the script receives SIGINT (Ctrl+C), the temporary file is not removed. Investigation shows that the trap on EXIT is not executed on SIGINT. Which modification should be made?
A new intern created a script to display the current user's home directory:
#!/bin/bash echo "Home directory: $home"
The script outputs 'Home directory: ' with nothing after the colon. What is the most likely cause?
Refer to the exhibit. ```bash #!/bin/bash for file in $(ls /etc/*.conf); do echo "Processing: $file" done ```