-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathda.sh
52 lines (36 loc) · 1.24 KB
/
da.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
#!/bin/bash
if [ $# -ne 1 ] #check the number of parameters
then
case $# in
0)
echo -e "You must specify the operation you want to make ( add | rem )."
;;
*)
echo "Too many arguments."
;;
esac
else
DESTINATION='/home/'$USER'/.bashrc' #where I put the .exe file
OUR_EXEC_LOCATION='#Add DiskAnalyzer to PATH \nexport PATH="'$(pwd)':$PATH"\n' #the needed command + location of our .exe file
case $1 in #check the parameter
add) #add the file
echo -e $OUR_EXEC_LOCATION >> $DESTINATION #append
echo "Successfully added."
;;
rem) #remove the file
positions=$(echo -e $(grep -n "$(echo -e $OUR_EXEC_LOCATION)" $DESTINATION | cut -d : -f 1)) #get the numbers of
#the lines where I find the OUR_EXEC_LOCATION variables
start=$(echo $positions | cut -d " " -f 1) #take the first index
finish=$(echo $positions | tr " " "\n" | tail -n 1) #take the last one
if [[ -z $start || -z $finish ]] #check if empty
then
echo "The file does not exist."
else
sed -i $start,$finish'd' $DESTINATION #for the interval [start, finish], delete all the lines
echo "Successfully removed."
fi
;;
*)
echo "Invalid parameter."
esac
fi