0
0
Bash Scriptingscripting~20 mins

What a shell script is in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Shell Script Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding the purpose of a shell script
What is the main purpose of a shell script?
ATo automate tasks by running a series of commands in sequence
BTo compile source code into executable programs
CTo create graphical user interfaces for applications
DTo store data in a structured database format
Attempts:
2 left
💡 Hint
Think about what you want to do when you repeat many commands often.
💻 Command Output
intermediate
1:30remaining
Output of a simple shell script
What will be the output when running this shell script? #!/bin/bash echo "Hello, friend!"
Bash Scripting
#!/bin/bash
 echo "Hello, friend!"
AError: command not found
Bhello, friend!
CHELLO, FRIEND!
DHello, friend!
Attempts:
2 left
💡 Hint
Look at the exact text inside the echo command.
📝 Syntax
advanced
2:00remaining
Identifying a syntax error in a shell script
Which option contains a syntax error in this shell script snippet? for i in 1 2 3 do echo $i done
Bash Scripting
for i in 1 2 3
 do
 echo $i
 done
Afor i in 1 2 3; do echo $i; done
Bfor i in 1 2 3 do echo $i done
C
for i in 1 2 3
do echo $i
done
Dfor i in 1 2 3; do echo $i done
Attempts:
2 left
💡 Hint
Check where semicolons or newlines are needed to separate commands.
🔧 Debug
advanced
2:00remaining
Why does this shell script fail to run?
This shell script is saved as 'myscript.sh' but fails to run with './myscript.sh'. What is the likely reason? #!/bin/bash echo "Running script"
AThe script file does not have execute permission
BThe shebang line is incorrect
CThe echo command is misspelled
DThe script must be run with 'bash myscript.sh' only
Attempts:
2 left
💡 Hint
Check the file permissions with 'ls -l'.
🚀 Application
expert
2:30remaining
Determining the output of a shell script with variables and conditionals
What is the output of this shell script? #!/bin/bash x=5 if [ $x -gt 3 ]; then echo "Greater" else echo "Smaller" fi
Bash Scripting
#!/bin/bash
 x=5
 if [ $x -gt 3 ]; then
   echo "Greater"
 else
   echo "Smaller"
 fi
ASyntax error
BSmaller
CGreater
DNo output
Attempts:
2 left
💡 Hint
Check the value of x and the condition in the if statement.