0
0
Bash Scriptingscripting~10 mins

First Bash script in Bash Scripting - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - First Bash script
Write script file
Make script executable
Run script in terminal
See output printed
Script ends
This flow shows how you write a bash script, make it runnable, execute it, and see the output.
Execution Sample
Bash Scripting
#!/bin/bash

echo "Hello, world!"
This script prints the text 'Hello, world!' to the terminal.
Execution Table
StepActionCommand/CodeOutput
1Write script file#!/bin/bash echo "Hello, world!"
2Make script executablechmod +x script.sh
3Run script./script.shHello, world!
4Script endsScript finishes running
💡 Script finishes after printing the message.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
script filenonecreated with codeexecutable permission setexecuted and output shownexists on disk
Key Moments - 3 Insights
Why do we need to add #!/bin/bash at the top?
The #!/bin/bash line tells the system to use the bash program to run the script, as shown in execution_table step 1.
What does chmod +x do?
chmod +x makes the script file executable, so the system allows running it, as seen in execution_table step 2.
Why do we run the script with ./script.sh?
Using ./ tells the system to run the script from the current folder, which is necessary unless the script is in a system path, as in execution_table step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is printed when the script runs?
AHello, world!
BScript finished
CError message
DNo output
💡 Hint
Check the Output column at Step 3 in the execution_table.
At which step do we make the script file executable?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the Action column in execution_table for 'Make script executable'.
If we forget to add #!/bin/bash, what might happen when running the script?
AThe script runs normally
BThe script deletes itself
CThe system may not know how to run it
DThe script outputs 'Hello, world!' twice
💡 Hint
Refer to key_moments about the purpose of #!/bin/bash.
Concept Snapshot
#!/bin/bash at top tells system to use bash
Write commands in script file (e.g., echo)
Make script executable with chmod +x
Run script with ./scriptname
Script prints output and ends
Full Transcript
This lesson shows how to create your first bash script. First, you write a file with the line #!/bin/bash at the top. This line tells the computer to use bash to run the script. Then you add commands like echo "Hello, world!" to print text. Next, you make the file executable using chmod +x. Finally, you run the script by typing ./script.sh in the terminal. The script runs and prints the message. This simple flow helps you start automating tasks with bash scripts.