S
S
Sergey2015-08-09 17:39:17
linux
Sergey, 2015-08-09 17:39:17

How to check if a line exists in a file in a bash script?

It is necessary, if there is no line in the config, add it. How to check for the presence of a line in a file using a bash script?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nadz Goldman, 2015-08-09
@butteff

Well, it's just...

#!/bin/bash
if grep -q myParam myConfigFile
  then echo "myParam string exist!"
else
 echo "Did not find string, adding"
echo "myParam = 0" >> myConfigFile
fi

T
TyzhSysAdmin, 2015-08-09
@POS_troi

sed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question