-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew-script
More file actions
executable file
·44 lines (33 loc) · 863 Bytes
/
Copy pathnew-script
File metadata and controls
executable file
·44 lines (33 loc) · 863 Bytes
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
#!/usr/bin/env bash
# *************************************
#
# New Script
# -> Create an executable shell script
#
# -------------------------------------
# Usage
# -------------------------------------
#
# `new-script bin/script-name` - creates a new script called 'script-name'
#
# *************************************
# -------------------------------------
# Errors
# -------------------------------------
set -o errexit
set -o nounset
set -o pipefail
# -------------------------------------
# Error Handling
# -------------------------------------
# Exit if file already exists
[ -e "$1" ] && echo "$1 already exists" && exit
# -------------------------------------
# Main
# -------------------------------------
if (( "$#" == 1 )); then
echo '#!/usr/bin/env bash' >> "$1"
else
echo "#!/usr/bin/env $2" >> "$1"
fi
chmod +x "$1"