Sample Shell script - filterbaks

The following is to illustrate that   .* files are only "hidden" by convention. We can pipe all our commands through a "filterbaks" program to make lots of other files also hidden by convention:

Might hide text editor backup files (things like file%, file~, file.bak):


Directory listing program:

	ls -al $* | grep -v "%$" | grep -v "~$" | grep -iv "\.bak$"
 

grep -v means match any line that -doesn't- contain the pattern
(i.e. filter out the lines that do)

$ means end-of-line
^ means start-of-line
. means any character
so \. means the literal character '.'

Do -precisely- the pattern that matches, no less and no more.
e.g. Don't match '.bak' or 'bak' in middle of filename like:
 'airflights.bakuwait.txt'



Might make it a separate file, called say "filterbaks":


       grep -v "%$" | grep -v "~$" | grep -iv "\.bak$"

so we can reuse it in directory listing:

	ls -al $* | filterbaks

and in other progs:

      if test `echo $i | filterbaks`
      then
       ...
Makes backup files invisible everywhere (until needed).

Finally, it would be more efficient to replace 3 programs piped together with 1 program (with more complex arguments). (Why would this be more efficient?)
We can do this using the "egrep" program, which can grep for boolean expressions. filterbaks can be rewritten as simply:

	egrep -iv  "%$|~$|\.bak$" 
where, inside the string here,   |   means "OR".