If I want to pass a program data files how can I distinguish the fact they are data files, not just strings of the file names. Basically I want to file redirect, but use command line arguments so I can a sure input is correct.
I have been using:
./theapp < datafile1 < datafile2 arg1 arg2 arg3 > outputfile
but I am wondering is it posible for it to look like this:
./the app datafile1 datafile2 arg1 arg2 arg3 > outputfile
Allowing the use of command line arguments.
It’s a little hard to combine two files into standard input like that. Better would be:
With
bash(at least), the second input redirection overrides the first, it does not augment it. You can see that with the two commands:When you use redirection, your application never even sees
>outputfile(for example). It is evaluated by the shell which opens it up and connects it to the standard output of the process you’re trying to run. All your program will generally see will be:Same with standard input, it’s taken care of by the shell.
The only possible problem with that first command above is that it combines the two files into one stream so that your program doesn’t know where the first ends and second begins (unless it can somehow deduce this from the content of the files).
If you want to process multiple files and know which they are, there’s a time-honoured tradition of doing something like:
and then having your application open and process the files itself. This is more work than letting the shell do it though.