-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialize
executable file
·57 lines (44 loc) · 951 Bytes
/
initialize
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# Function to display usage and exit
usage() {
echo "Usage: $0 <number (1-25)>"
exit 1
}
# Check if exactly one argument is provided and is a valid number
if [ "$#" -ne 1 ] || [[ ! "$1" =~ ^[0-9]+$ ]]; then
usage
fi
# Check if the number is less than or equal to 25
if [ "$1" -gt 25 ]; then
echo "The number must be 25 or less"
exit 1
fi
# Format the number to always have two digits
NUMBER=$(printf "%02d" "$1")
# Define the directory and file path
DIR="$NUMBER"
FILE="$DIR/$NUMBER.go"
# Check if the file already exists
if [ -f "$FILE" ]; then
echo "File $FILE already exists"
exit 1
fi
# Create the directory and file
mkdir -p "$DIR"
cat <<EOF > "$FILE"
package main
import "fmt"
func part1() int {
return 0
}
func part2() int {
return 0
}
func main() {
fmt.Println("Part 1:", part1())
fmt.Println("Part 2:", part2())
}
EOF
echo "File created at $FILE"
# Run the generated Go program
go run "$FILE"