-
Notifications
You must be signed in to change notification settings - Fork 0
/
myscript.sh
79 lines (72 loc) · 1.51 KB
/
myscript.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
71
72
73
74
75
76
77
78
79
#!/bin/bash
# myscript.sh
#Description: Creates a new bash script with execution permission
# and opens nano
#AUTHOR: Charles P. Cross
#Usage: -d : option deletes a script ./newscript.sh -d /home/users/scripts script.sh
# Pass script name optional to create a new script ./newscript.sh myscript.sh
# Script is created in BASE directory which you need to specify
# If file already exists it won't be overwritten
##################################################
BASE=$1
FILE=$2
#Check for option
if [ "$FILE" = "-d" ]
then
FILE=$2
if [[ -z "$FILE" ]]
then
echo "What is the name of the script to DELETE? ex.(myscript.sh): "
read FILE
fi
if [[ -n "$FILE" ]]
then
# Delete file if it exists
if [[ -e "$BASE$FILE" ]]
then
rm $BASE$FILE
echo "$BASE$FILE has been deleted permanently!"
echo "Script is Exiting Now....!"
exit
else
echo "File doesn't exist! $BASE$FILE"
exit
fi
else
echo "No file specified for deletion!"
echo "Script is Exiting Now....!"
exit
fi
fi
#End of delete option
#Get Filename from input
if [[ -z "$FILE" ]]
then
echo "What is the name of your new script? ex.(myscript.sh): "
read FILE
fi
#If File was specified
if [[ -n "$FILE" ]]
then
if [[ ! -e $BASE$FILE ]]
then
# Create Script File
echo "#!/bin/bash
#FILENAME: $FILE
#AUTHOR:
#EMAIL:
#LICENSE: GNU GENERAL PUBLIC LICENSE
#USAGE:
#DESCRIPTION:
##############################
" > $BASE$FILE
fi
# Set Permissions for Owner Execution
chmod 700 $BASE$FILE
nano $BASE$FILE
echo "Script Location: $BASE$FILE"
exit
else
echo "No filename was provided FAIL!"
exit
fi