Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell redirection vs explicit file handling code

Tags:

c

redirect

shell

I am not a native english speaker so please excuse the awkward title of this question. I just not knew how to phrase it better.

I am on a FreeBSD box and I have a little filter tool written in C which reads a list of data via stdin and outputs a processed list via stdout. I invoke it somewhat like this: find . -type f | myfilter > /tmp/processed.txt.

Now I want to give my filter a little bit more exposure and publish it. Convention says that tools should allow something like this: find . -type f | myfilter -f - -o /tmp/processed.text

This would force me to write code that simply is not needed since the shell can do the job, therefore I tend to leave it out.

My question is: Do I miss some argument (other but convention) why the reading and writing of files should be done in my code an not delegated to shell redirection?

like image 849
enoch Avatar asked Oct 10 '22 21:10

enoch


1 Answers

There's absolutely nothing wrong with this. Your filter would have an interface similar to, say, c++filt.

You might consider file handling if you wanted to automatically choose an output file based on the name of an input file or if you wanted to special handling for processing multiple files in a single command.

If you don't want to do any either of these then there's nothing wrong with being a simple filter. Anyone can provide a set of simple shell wrappers to provide a cmd infile outfile syntax if they wish.

like image 73
CB Bailey Avatar answered Nov 13 '22 10:11

CB Bailey