0

I have a file that contain this line

SELINUX = enforce

I want to change this by given input to permissive How i do that without demage?

Mr iSvALiD
  • 67
  • 1
  • 10

1 Answers1

0
If [[ "$1" == "Y"]]
then
    sed -ri 's/(^.*SELINUX=)(.*$)/\1enforce/' file
else
    sed -ri 's/(^.*SELINUX=)(.*$)/\1permissive/' file
fi

If the first passed parameter ($1) is equal to "Y" use sed to split SELINUX line into to 2 sections. Substitute the line for the first section followed by "enforce". If the passed parameter is not "Y" substitute the line for the first section followed by "permissive".

Raman Sailopal
  • 12,320
  • 2
  • 11
  • 18