-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_script.sh
More file actions
executable file
·58 lines (40 loc) · 979 Bytes
/
create_script.sh
File metadata and controls
executable file
·58 lines (40 loc) · 979 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# is there any argument
if [[ ! $1 ]] ; then
echo "missing argument"
exit 1
fi
scriptname="$1"
bindir="${HOME}/bin"
filename="${bindir}/${scriptname}"
if [[ -e $filename ]] ; then
echo "file ${filename} already exists"
exit 1
fi
# type of the scriptname(command)
if type "$scriptname" 2> /dev/null 2>&1; then # redirect error given by type to dev/null
echo " there is aleady a command with name ${scriptname}"
exit 1
fi
# check bin directory
if [[ ! -d $bindir ]]; then
#if not create bin dicrectory
if mkdir "$bindir"; then
echo "created ${bindir}" # we write this {} inside the string"
else
echo " could not create ${bindir}"
exit 1
fi
fi
#create s script with a single line
echo "#!/bin/bash" >"$filename"
# add executable permission
chmod u+x "$filename"
#Open with Editor
if [[ $EDITOR ]]; then
$EDITOR "$filename"
else
echo "script created; not starting editor because \$EDITOR is not set"
fi
echo " end of script"
exit 0