I am writing my own shell in C. It's fairly simple, but I want to implement three more commands. First being commands, with or without arguments, whose output is redirected to a file. Second being, a command, with or without arguments, whose output is appended to a file. Lastly, a command, with or without arguments, whose input is redirected from a file.
All of these commands can be implemented using the syscalls freopen()
, dup()
and dup2()
.
An example of the first command could be ls -l > fileName.txt
.
This should take the output of the command and put it in fileName.txt
.
An example of the second command could be ls -l >> fileName.txt
.
This should take the output of the command and append it to whatever is in the file fileName.txt
.
An example of the last command could be bc < file
. This takes the output of the command and put it in the named file.
This shouldn't be too hard to implement, but for some reason I don't know how to do it and am having some serious trouble. Could someone help me out?