Hook scripting
- Git course
- Expert
- Lesson 5/32
- 4 min
Learn to write hook scripts.
What Are Hook Scripts?
#!/bin/bash
echo "Hook executed"Shell Scripts and Hook Files
chmod +x .git/hooks/example-hookPractice Write a Simple Hook Script
Create a hook script that runs with Bash. Specify the Bash interpreter on the first line and print `Hook executed` to the terminal.
Starter code
echo "Mesaj"Sample solution
#!/bin/bash
echo "Hook çalıştı"Expected output
Hook çalıştı
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What property must a hook script have to run?
- It must have executable permissions Correct answer
- It must contain HTML
- It must be uploaded to a remote repository
- It must only be an empty file
Explanation: A hook file must have appropriate execution permissions so Git can run it.
2 Complete the Bash Hook File
#!/bin/bash
_____ "Hook hazır"____
#!/bin/bash
_____ "Hook hazır"echo
Explanation: In Bash, the `echo` command prints text to the terminal.
3 Match the Hook Script Components
| Term | Meaning |
|---|---|
Shebang |
Identifies the interpreter |
Bash |
Is a shell environment |
chmod +x |
Grants execution permission |
.git/hooks |
Is the directory for hook files |