Recall & Review
beginner
What is the command to make a script executable in Bash?
Use
chmod +x scriptname.sh to give execute permission to the script.Click to reveal answer
beginner
How do you run a Bash script located in the current directory?
Run it by typing
./scriptname.sh in the terminal.Click to reveal answer
beginner
Why do you need
./ before the script name when running it?Because the current directory is not in the PATH by default,
./ tells the shell to run the script from here.Click to reveal answer
beginner
What does the first line
#!/bin/bash in a script do?It tells the system to use the Bash shell to run the script. This line is called the shebang.
Click to reveal answer
intermediate
Can you run a script without making it executable? How?
Yes, by running
bash scriptname.sh or sh scriptname.sh you can run the script without changing permissions.Click to reveal answer
What command makes a Bash script executable?
✗ Incorrect
The
chmod +x command adds execute permission to the script.How do you run a script named
myscript.sh in the current folder?✗ Incorrect
You run it with
./myscript.sh because the current directory is not in PATH.What is the purpose of the shebang line
#!/bin/bash?✗ Incorrect
The shebang tells the system to use Bash to run the script.
If you do not want to change permissions, how can you run a script?
✗ Incorrect
Running
bash script.sh runs the script without needing execute permission.Why do you need to type
./ before the script name?✗ Incorrect
The shell does not look in the current folder unless you specify
./.Explain step-by-step how to prepare and run a Bash script from creating it to executing it.
Think about file creation, permissions, and running commands.
You got /4 concepts.
Describe why the current directory is not searched by default when running commands and how to run scripts in the current directory.
Consider how the shell finds commands.
You got /3 concepts.