\"tee\" is a Linux shell command that will take the output of a command and rout
ID: 3591640 • Letter: #
Question
"tee" is a Linux shell command that will take the output of a command and route it into a stdout AS WELL AS to multiple files or commands. For example: cat file.txt | tee > (do_stuff1_to_cat_output) > (do_stuff2_to_cat_output) > (do_stuff2_to_cat_output). For the third assignment, you are implementing your own shell: mysh. Write a pseudo-code implementation of this command as if you would be implementing it as a part of the assignment 3. for your sell (mysh). Use kernel pipes, dup, dup2 system calls to accomplish this. Let's say your code will implement new operator "||" that will pipe an output of a proceeding command to stdout and any number of commands afterwards separated by multiple ">". For example: $ echo "this is my text" || grep this > grep my > wc-c Here text "this is my text" will be echo-ed on stdout and it is also used by grep as its input to do "grep this" and "grep my" and "wc-c" (wordcount command) the output should be:
___________________________________
$ this is my text
$ this is my text
$ this is my text
$16
___________________________________
a.) Write pseudo-code for handing "||" with two commands following the special character "||"
b.) Generalize the command for any number of commands following the special character "||"
Explanation / Answer
You can also use tee command to store the output of a command to a file and redirect the same output as an input to another command.
The following command will take a backup of the crontab entries, and pass the crontab entries as an input to sed command which will do the substituion. After the substitution, it will be added as a new cron job.
Misc Tee Command Operations
By default tee command overwrites the file. You can instruct tee command to append to the file using the option –a as shown below.
You can also write the output to multiple files as shown below.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.