0
0
Bash Scriptingscripting~20 mins

Why Bash scripting automates Linux tasks - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bash Automation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Bash script?
Consider this Bash script that automates a simple task of listing files and counting them:
Bash Scripting
#!/bin/bash
count=$(ls | wc -l)
echo "Number of files: $count"
ASyntax error near unexpected token `|'
BNumber of files: 0
Cls: command not found
DNumber of files: <actual number of files in current directory>
Attempts:
2 left
💡 Hint
The script counts files in the current directory using ls and wc commands.
🧠 Conceptual
intermediate
1:30remaining
Why is Bash scripting useful for Linux task automation?
Which of the following best explains why Bash scripting is commonly used to automate Linux tasks?
ABecause Bash scripts run faster than compiled programs
BBecause Bash scripts can combine multiple Linux commands easily to automate workflows
CBecause Bash scripts require no permissions to run on any system
DBecause Bash scripts can only be run on Windows systems
Attempts:
2 left
💡 Hint
Think about how Bash scripts use existing Linux commands.
🔧 Debug
advanced
2:00remaining
What error does this Bash script produce?
Look at this script intended to automate file backup but it has a bug:
Bash Scripting
#!/bin/bash
backup_dir=/backup
mkdir -p $backup_dir
cp /home/user/*.txt $backup_dir
ASyntax error: unexpected end of file
Bcp: cannot stat '/home/user/*.txt': No such file or directory
Cmkdir: cannot create directory ‘/backup’: Permission denied
DNo error, script runs successfully
Attempts:
2 left
💡 Hint
Consider permissions when creating directories outside your home folder.
🚀 Application
advanced
2:30remaining
Which script snippet correctly automates checking if a service is running and restarts it if not?
You want to automate checking if 'nginx' service is active and restart it if it is not. Which snippet does this correctly?
Aif systemctl is-active --quiet nginx; then echo 'Running'; else systemctl restart nginx; fi
Bif systemctl is-active nginx; then systemctl restart nginx; else echo 'Running'; fi
Csystemctl restart nginx if not systemctl is-active nginx
Dif [ $(systemctl is-active nginx) = 'inactive' ]; then echo 'Running'; fi
Attempts:
2 left
💡 Hint
Check the correct use of systemctl is-active with --quiet and conditional logic.
🧠 Conceptual
expert
2:00remaining
What is the main advantage of using Bash scripting over manual command execution for Linux task automation?
Choose the best explanation for why Bash scripting is preferred for automating Linux tasks instead of typing commands manually each time.
ABash scripts can be scheduled to run automatically and repeat tasks without human intervention
BBash scripts always run faster than manual commands typed in terminal
CBash scripts can only be run by system administrators
DBash scripts do not require any knowledge of Linux commands
Attempts:
2 left
💡 Hint
Think about automation and repetition benefits.