[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] scripting



On Sat, 25 Sep 2010 12:36:56 , Vincent Rivière <vincent.riviere@freesbee.fr> wrote:
> Peter Slegg wrote:
> > It seems to work when using a copy of ited.conf in /home  but doesn't
> > work when I change FILE to point to /etc/inetd.conf ... find . -name
> > $FILE -type f -exec perl -pi -e $REPL {} \;
>
> Ask yourself why you use the find command then you will have the answer.

Answering a question with a question ?


Because having read half a dozen recommendations of ways to do things
this sort of thing, it came out as the best way of doing it. I haven't
used "find" before although the man pages look like they were written
by someone whose first language was gibberish.


" find searches the directory tree rooted at each given file
  name by evaluating the given expression from left to right,
  according to the rules of precedence  (see  section
  OPERATORS),  until the outcome is known (the left hand side
  is false for and operations, true for or), at which
  point find moves on to the next file name."

My earlier version used sed

#!/bin/bash -x
FILE="./test.conf"
if [ "$2" = "on" ];then
  REPL="s/#"$1"/"$1"/g"
else
  REPL="s/"$1"/#"$1"/g"
fi

#sed -e 's/#$1/$1/g' inetd.conf > test.conf
sed -e $REPL $FILE #> $FILE

grep -v '^#' $FILE