Currently I'm coding a small shell (redirection, pipes, exec, etc.). Been trying to figure out the steps the Linux shell takes in addressing I/O redirection.
Some questions on what I need help on:
In which direction does the shell read from the command line when it is looking for the redirection? Left to right or the opposite? Uses recursion?
What are the cases the shell needs to look for? (not sure if there are many or just a couple that can encompass a lot of variation)
Anyways, some I can think of are (correct me if I'm wrong):
cmd > file1 # stdout of cmd goes to file
cmd file1 > file2 # stdout of cmd with file1 as an argument goes to file2
cmd file2 < file1 # stdin on file2 comes from file1
Now I don't know the process on the following cases (as in how the shell looks for and handles these). The steps the shell takes are unbeknown to me
cmd file2 > file3 < file1 # using "tee" in place of "cmd" I don't know
# how to do the dups and when to exec
cmd file2 < file3 > file1 # same ^