-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_bash.sh
More file actions
executable file
·66 lines (58 loc) · 1.55 KB
/
create_bash.sh
File metadata and controls
executable file
·66 lines (58 loc) · 1.55 KB
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
#!/bin/bash
#
# Time-stamp: <Monday 2023-04-07 11:48:10 +1000 Jess Moore>
#
# Creates bash file with timestamp, name and brief description
#
# Usage: create_bash.sh new_script.sh "Does xyz"
# shellcheck disable=SC2012
SOURCE=$(ls -l "$(which "$0")" | awk '{print $11}')
function usage() {
echo "Usage: $(basename "$0") 'file' 'desc'"
echo ""
echo "Description: This script creates a bash script "
echo " with name [file].sh and standard format "
echo " including datetime author attribution "
echo " stamp, usage line, the user provided"
echo " one line description of what the script"
echo " does. "
echo ""
echo "Arguments:"
echo " file: Name of script (excluding .sh)."
echo " desc: One line description of script."
echo ""
echo "Source: $SOURCE"
echo ""
exit 1 # Exit with a non-zero status to indicate an error
}
if [[ $# -eq 0 || $* == *"help"* || $* == *"-h"* ]]; then
usage
fi
NAME=$(id -F)
NOW=$(date "+%A %Y-%m-%d %H:%M:%S")
FILEBASE=$1
DESC=$2
FILENAME=$FILEBASE.sh
cat > "${FILENAME}" << EOF
#!/bin/bash
#
# Time-stamp: ${NOW} ${NAME}
#
# ${DESC}
#
# Usage: ${FILENAME} [args...]
function usage() {
echo "Usage: ${FILENAME} [args...]"
echo ""
echo "Description: ${DESC}."
echo ""
echo "Arguments:"
echo " arg1: ..."
echo " arg2: ..."
echo ""
exit 1 # Exit with a non-zero status to indicate an error
}
if [[ \$# -eq 0 || \$* == *"help"* || \$* == *"-h"* ]]; then
usage
fi
EOF