0
0
Bash Scriptingscripting~5 mins

Running scripts in Bash Scripting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Achmod +x script.sh
Brun script.sh
Cexecute script.sh
Dbash +x script.sh
How do you run a script named myscript.sh in the current folder?
Abash ./myscript.sh
Bmyscript.sh
C./myscript.sh
Drun myscript.sh
What is the purpose of the shebang line #!/bin/bash?
ATo comment the first line
BTo name the script
CTo make the script executable
DTo tell the system which shell to use to run the script
If you do not want to change permissions, how can you run a script?
Abash script.sh
B./script.sh
Cchmod script.sh
Dexecute script.sh
Why do you need to type ./ before the script name?
ABecause it is part of the script name
BBecause current directory is not in PATH by default
CBecause it makes the script executable
DBecause it is a command to run scripts
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.