-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_script_template.sh
executable file
·70 lines (62 loc) · 1.69 KB
/
bash_script_template.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# ------------
# Script Name: script_name.sh
# Author: Your Name
# Version: 1.0
# Date: 2024-06-13
# Optargs
# -------
# -h: Display help message
# -I: Input file path
# -o: Output file path
# --long-option: Long option description
# Check for required arguments
if [ $# -eq 0 ]; then
echo "Error: No arguments provided."
echo "Usage: $0 [-h] [-I <file_path>] [-o <file_path>] [--long-option]"
exit 1
fi
# Process the input options
while getopts ":hi:o:" opt; do
case $opt in
h) # Display help message
echo "Usage: $0 [-h] [-I <file_path>] [-o <file_path>] [--long-option]"
exit 0
;;
I) # Input file path
INPUT_FILE=$OPTARG
;;
o) # Output file path
OUTPUT_FILE=$OPTARG
;;
:) # Option requires an argument
echo "Error: Option -$OPTARG requires an argument."
echo "Usage: $0 [-h] [-I <file_path>] [-o <file_path>] [--long-option]"
exit 1
;;
\?) # Invalid option
echo "Error: Invalid option -$OPTARG."
echo "Usage: $0 [-h] [-I <file_path>] [-o <file_path>] [--long-option]"
exit 1
;;
esac
done
# Check for input file
if [ -z "$INPUT_FILE" ]; then
echo "Error: No input file provided."
echo "Usage: $0 [-h] [-I <file_path>] [-o <file_path>] [--long-option]"
exit 1
fi
# Check for output file
if [ -z "$OUTPUT_FILE" ]; then
OUTPUT_FILE="output.txt"
fi
# Check for long options
if [[ $1 == *"--"* ]]; then
if [[ $1 == *"--long-option"* ]]; then
LONG_OPTION=$1
shift
fi
fi
# Perform script operations
# ...