0
0
Bash Scriptingscripting~20 mins

Running scripts in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Script Runner 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 script execution command?
You have a script named hello.sh with the following content:
#!/bin/bash
echo "Hello, world!"

What will be the output if you run bash hello.sh in the terminal?
Bash Scripting
#!/bin/bash
echo "Hello, world!"
Abash: hello.sh: command not found
BHello, world!
CNo output, script runs silently
DError: Permission denied
Attempts:
2 left
💡 Hint
Running a script with bash executes the commands inside it and prints output.
💻 Command Output
intermediate
2:00remaining
What happens when you run a script without execute permission?
You have a script myscript.sh with content:
#!/bin/bash
echo "Run me!"

The file does NOT have execute permission. What happens if you run ./myscript.sh?
Bash Scripting
#!/bin/bash
echo "Run me!"
Abash: ./myscript.sh: Permission denied
BRun me!
CNo output, script runs silently
Dbash: myscript.sh: command not found
Attempts:
2 left
💡 Hint
Trying to run a file without execute permission causes a permission error.
📝 Syntax
advanced
2:00remaining
Which command correctly runs a script named script.sh located in the current directory?
You want to run script.sh from the terminal. Which command will run it correctly assuming it has execute permission?
Ascript.sh
Bbash ./script.sh
C/script.sh
D./script.sh
Attempts:
2 left
💡 Hint
Scripts in the current directory need a path prefix to run directly.
🔧 Debug
advanced
2:00remaining
Why does this script fail to run with ./runme.sh?
Script runme.sh content:
echo "Start"
echo "Done"

You try ./runme.sh but get:
bash: ./runme.sh: Permission denied
What is the cause?
AThe script lacks execute permission
BThe script has a syntax error
CThe script file is empty
DThe script is missing the shebang line
Attempts:
2 left
💡 Hint
Permission denied means the OS won't let you run the file.
🚀 Application
expert
3:00remaining
What is the output of this script execution with environment variable?
Given the script envtest.sh:
#!/bin/bash
echo "User is: $USER"

You run:
USER=guest ./envtest.sh
What is the output?
Bash Scripting
#!/bin/bash
echo "User is: $USER"
AUser is: (empty line)
BUser is: $USER
CUser is: guest
Dbash: ./envtest.sh: Permission denied
Attempts:
2 left
💡 Hint
Setting an environment variable before a command overrides it inside the script.