@@ -49,7 +49,6 @@ delete_line_from_file() {
4949 if [ -f $2 ]
5050 then
5151 sudo sed -i " /$1 /d" $2
52- feedback " deleted $1 from $2 "
5352 fi
5453}
5554
@@ -58,26 +57,55 @@ insert_before_line_in_file() {
5857 # second argument is a partial match of the line we need to find to insert before
5958 # third arument is filename
6059
61- feedback " Inserting $1 before $2 in $3 "
6260 if [ -f $3 ]
6361 then
64- feedback " sudo sed -i '/$2 /i $1 ' $3 "
6562 sudo sed -i " /$2 /i $1 " $3
6663 fi
6764}
65+
6866add_line_to_end_of_file () {
6967 # first parameter is what to add
7068 # second parameter is filename
7169 if [ -f $2 ]
7270 then
73- echo $1 >> $2
71+ echo " $1 " >> " $2 "
7472 fi
7573}
7674
75+ replace_first_this_with_that_in_file () {
76+ # replaces the first occurence
77+ # first parameter is the string to be replaced
78+ # second parameter is the string which replaces
79+ # third parameter is the filename
80+ if grep -q " $1 " $3
81+ then
82+ sudo sed -i ' /$1/c\$2' $3
83+ return 0
84+ else
85+ # feedback "Line - $1 not found"
86+ return 1
87+ fi
88+ }
89+ replace_all_this_with_that_in_file (){
90+ # does a global replace
91+ # first argument: what needs to be replaced
92+ # second argument: the new stuff
93+ # third argument: the file in question
94+ # returns 0 if file exists (may or may not have succeeded in the substitution)
95+ # return 1 if file does not exists
96+ # feedback "replacing $1 with $2 in $3"
97+ if file_exists " $3 "
98+ then
99+ sudo sed -i " s/$1 /$2 /g" " $3 "
100+ return 0
101+ else
102+ return 1
103+ fi
104+ }
105+
77106find_in_file () {
78107 # first argument is what to look for
79108 # second argument is the filename
80- feedback " looking for $1 in $2 "
81109 if grep -q " $1 " $2
82110 then
83111 return 0
@@ -95,7 +123,7 @@ file_exists() {
95123 # Only one argument: the file to look for
96124 # returns 0 on SUCCESS
97125 # returns 1 on FAIL
98- if [ -f $1 ]
126+ if [ -f " $1 " ]
99127 then
100128 return 0
101129 else
@@ -117,22 +145,19 @@ file_does_not_exists(){
117145 # Only one argument: the file to look for
118146 # returns 0 on SUCCESS
119147 # returns 1 on FAIL
120- feedback " looking for $1 "
121148 if [ ! -f $1 ]
122149 then
123- feedback " not found $1 "
124150 return 0
125151 else
126- feedback " found $1 "
127152 return 1
128153 fi
129154}
130155
131156delete_file (){
132157 # One parameter only: the file to delete
133- if file_exists $1
158+ if file_exists " $1 "
134159 then
135- sudo rm $1
160+ sudo rm " $1 "
136161 fi
137162}
138163
@@ -157,17 +182,17 @@ wget_file() {
157182#
158183# ########################################################################
159184create_folder (){
160- if ! folder_exists
185+ if ! folder_exists " $1 "
161186 then
162- mkdir $1
187+ sudo mkdir " $1 "
163188 fi
164189}
165190
166191folder_exists (){
167192 # Only one argument: the folder to look for
168193 # returns 0 on SUCCESS
169194 # returns 1 on FAIL
170- if [ -d $1 ]
195+ if [ -d " $1 " ]
171196 then
172197 return 0
173198 else
@@ -176,8 +201,8 @@ folder_exists(){
176201}
177202
178203delete_folder (){
179- if folder_exists $1
204+ if folder_exists " $1 "
180205 then
181- sudo rm -r $1
206+ sudo rm -r " $1 "
182207 fi
183208}
0 commit comments