Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Read and follow the exercise Lab 5.0 Input/output redirection and pipes on a Linux terminal. Provide the screen capture of the exercise on your terminal,
Read and follow the exercise Lab 5.0 Input/output redirection and pipes on a Linux terminal. Provide the screen capture of the exercise on your terminal, and explain how the output redirection operators are used section 5.5 below.
Lab 5.0 Input/output redirection and pipes The The two major means of interaction between a Unix application and the user are the keyboard as an input device, and the terminal as an output device. Applications can read input strings from the keyboard using function scanf in C, or global object std::cin in C++. Likewise, applications can dump strings into the terminal using function printf in C, or global object std::cout in C++. In Unix operating systems, the keyboard and terminal are represented by two virtual device files, named standard input and standard output, respectively. Unix allows us to redirect the standard input and output of a program into other files. If we choose to do so, a program that expects to read its input from the keyboard will instead read the content of an existing file. Or the output that is displayed on the terminal under normal circumstances can instead be dumped directly into a file. The shell provides a dedicated syntax for input/output redirection through the operators. Try and type the following command in the shell: $ echo "Hello" As you learned in the previous lab assignment, echo is a command that prints its arguments into the standard output. In this case, string Hello is dumped into the terminal. Using operator >, we can redirect this output into a file named message.txt as follows: $ echo "Hello" > message.txt If file output.txt existed before running the command above, it is overwritten and its content is fully replaced with string Hello. If you run the command above multiple times, you will notice that the content of file output.txt does not change as compared to the first time. If, on the contrary, you want to keep the previous content of file message.txt and append string Hello to it, you can use operator>> instead, as follows: echo "Hello" >> message.txt To illustrate the redirection of the standard input, let us use command wc. When you run this command without arguments, it reads lines of text from the standard input, and then shows a message counting the number of lines, words, and characters entered. When you enter text from the keyboard you need to notify wc about the end of the input with an EOF (end-of-file) character, which you can provide by pressing Control+D. Example: $ WC Hello How are you? 2 4 19 If, instead of reading the input from the keyboard, you want to read it directly from file message.txt, you can use operator $FILEPATH/unexport 2>/devull echo 10 > $FILEPATH/unexport 2>/devull echo 11 > $FILEPATH/unexport 2>/devull echo 12 > $FILEPATH/unexport 2>/devull echo 0 > $FILEPATH/unexport 2>/devull echo 13 > $FILEPATH/export echo 10 > $FILEPATH/export echo 11 > $FILEPATH/export echo 12 > $FILEPATH/export echo 0 > $FILEPATH/export echo out > SFILEPATH/gpio13/direction echo out > SFILEPATH/gpio10/direction echo out > SFILEPATH/gpio11/direction echo out > SFILEPATH/gpio12/direction echo out > $FILEPATH/gpioo/direction "2>/devull" redirects stderr to '/devull" device. The null device takes any input you want and suppresses it throws it away). You can assign execution permissions to the shell script with the following command: $ chmod +x gpio-init.sh And finally, you can invoke the script every time the ZedBoard reboots with the following command: $ sudo ./gpio-init.sh
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started