Skip to content

Commit fc7b04e

Browse files
committed
Add bash starter template
1 parent 53e0f18 commit fc7b04e

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: Starter template for a Bash script
3+
date: 2025-12-30
4+
topics:
5+
- bash
6+
---
7+
8+
```sh
9+
#!/usr/bin/env bash
10+
11+
# Exit immediately if any command exits with non-zero status
12+
set -e
13+
# Exit if an undefined variable is used
14+
set -u
15+
# Fail if any command in a pipeline fails (not just the last one)
16+
set -o pipefail
17+
18+
# Print line at which the script failed, if it failed (due to "set -e").
19+
trap 'print_error "Script failed at line $LINENO"' ERR
20+
21+
# Configuration
22+
SCRIPT_NAME="$(basename "$0")"
23+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24+
25+
# Colors for output (optional)
26+
readonly RED='\033[0;31m'
27+
readonly YELLOW='\033[1;33m'
28+
readonly CYAN='\033[0;36m'
29+
readonly NC='\033[0m' # No Color
30+
31+
print_error() {
32+
echo -e "${RED}$*${NC}" >&2
33+
}
34+
35+
print_warn() {
36+
echo -e "${YELLOW}$*${NC}" >&2
37+
}
38+
39+
print_title() {
40+
echo -e "${CYAN}$*${NC}"
41+
echo
42+
}
43+
44+
###########################################################################################
45+
#
46+
# Main Script
47+
#
48+
###########################################################################################
49+
```

0 commit comments

Comments
 (0)