Standard I/O and Pipes

Red Hat Linux Essentials Shortcuts, Variables, Shell Scripting, Standard I/O and Pipes
11 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€46.73
List Price:  €65.43
You save:  €18.69
£39.55
List Price:  £55.38
You save:  £15.82
CA$68.39
List Price:  CA$95.75
You save:  CA$27.36
A$76.50
List Price:  A$107.11
You save:  A$30.60
S$68.11
List Price:  S$95.36
You save:  S$27.25
HK$391.33
List Price:  HK$547.90
You save:  HK$156.56
CHF 45.19
List Price:  CHF 63.27
You save:  CHF 18.08
NOK kr551.82
List Price:  NOK kr772.60
You save:  NOK kr220.77
DKK kr348.47
List Price:  DKK kr487.88
You save:  DKK kr139.41
NZ$84.17
List Price:  NZ$117.84
You save:  NZ$33.67
د.إ183.60
List Price:  د.إ257.06
You save:  د.إ73.45
৳5,499.99
List Price:  ৳7,700.43
You save:  ৳2,200.43
₹4,169.28
List Price:  ₹5,837.33
You save:  ₹1,668.04
RM238.32
List Price:  RM333.67
You save:  RM95.35
₦66,060.50
List Price:  ₦92,489.99
You save:  ₦26,429.48
₨13,951.51
List Price:  ₨19,533.24
You save:  ₨5,581.72
฿1,848.80
List Price:  ฿2,588.46
You save:  ฿739.66
₺1,625.07
List Price:  ₺2,275.23
You save:  ₺650.15
B$255.76
List Price:  B$358.08
You save:  B$102.32
R938.81
List Price:  R1,314.42
You save:  R375.60
Лв91.38
List Price:  Лв127.95
You save:  Лв36.56
₩68,890.62
List Price:  ₩96,452.39
You save:  ₩27,561.76
₪190.87
List Price:  ₪267.23
You save:  ₪76.36
₱2,881.72
List Price:  ₱4,034.64
You save:  ₱1,152.92
¥7,903.16
List Price:  ¥11,065.06
You save:  ¥3,161.90
MX$857.83
List Price:  MX$1,201.03
You save:  MX$343.20
QR182.72
List Price:  QR255.83
You save:  QR73.10
P689.81
List Price:  P965.79
You save:  P275.98
KSh6,639.79
List Price:  KSh9,296.24
You save:  KSh2,656.45
E£2,392.59
List Price:  E£3,349.82
You save:  E£957.23
ብር2,876.01
List Price:  ብር4,026.64
You save:  ብር1,150.63
Kz41,694.65
List Price:  Kz58,375.85
You save:  Kz16,681.20
CLP$47,588.94
List Price:  CLP$66,628.33
You save:  CLP$19,039.38
CN¥362.20
List Price:  CN¥507.11
You save:  CN¥144.91
RD$2,937.78
List Price:  RD$4,113.13
You save:  RD$1,175.34
DA6,709.29
List Price:  DA9,393.54
You save:  DA2,684.25
FJ$113.10
List Price:  FJ$158.35
You save:  FJ$45.25
Q389.77
List Price:  Q545.71
You save:  Q155.94
GY$10,484.28
List Price:  GY$14,678.83
You save:  GY$4,194.55
ISK kr7,005.56
List Price:  ISK kr9,808.34
You save:  ISK kr2,802.78
DH506.20
List Price:  DH708.72
You save:  DH202.52
L888.32
List Price:  L1,243.72
You save:  L355.39
ден2,874.95
List Price:  ден4,025.16
You save:  ден1,150.21
MOP$404.09
List Price:  MOP$565.76
You save:  MOP$161.67
N$945.52
List Price:  N$1,323.80
You save:  N$378.28
C$1,844.23
List Price:  C$2,582.07
You save:  C$737.84
रु6,681.04
List Price:  रु9,353.99
You save:  रु2,672.95
S/188.25
List Price:  S/263.57
You save:  S/75.31
K193.43
List Price:  K270.82
You save:  K77.39
SAR187.48
List Price:  SAR262.49
You save:  SAR75
ZK1,328
List Price:  ZK1,859.31
You save:  ZK531.30
L232.80
List Price:  L325.94
You save:  L93.14
Kč1,174.50
List Price:  Kč1,644.39
You save:  Kč469.89
Ft18,330.20
List Price:  Ft25,663.75
You save:  Ft7,333.54
SEK kr544.35
List Price:  SEK kr762.14
You save:  SEK kr217.78
ARS$43,786.41
List Price:  ARS$61,304.48
You save:  ARS$17,518.06
Bs347.54
List Price:  Bs486.59
You save:  Bs139.04
COP$198,222.27
List Price:  COP$277,527.04
You save:  COP$79,304.77
₡25,463.28
List Price:  ₡35,650.64
You save:  ₡10,187.35
L1,237.47
List Price:  L1,732.56
You save:  L495.08
₲373,144.52
List Price:  ₲522,432.19
You save:  ₲149,287.66
$U1,931.55
List Price:  $U2,704.33
You save:  $U772.77
zł201.47
List Price:  zł282.07
You save:  zł80.60
Already have an account? Log In

Transcript

So now we are going to learn about standard input output and pipes for RTL. So let's start the input output could be channelized into programs, there are three input output channels is standard input stdio h that is provided by keyword a standard output or STD out that is provided on terminal window by default, the standard error STD er, which is directed to a terminal window by default, however, we can generalize the input and output to devices or programs or to text files. So, we are going to learn about how we can do so. We can redirect output to a file output of a standard output or a standard error which can be redirected to files. So the syntax for writing this is provided a command the command which you want to execute the operator for standard output or standard error and the filename where the output or error has to be transferred.

So the supported operators include a redirection of the standard output to a file provided by arrow symbol on the right hand side. Then there is a redirection option for a standard error to a file, which is provided by writing to and directed symbol on the right hand side. Then we can redirect all the outputs including errors and output program output to the file by providing ampersand symbol and right hand side arrow symbol. So let's take an example. Suppose we want to execute the find command on a certain path. I like changing the password we can do stored the output of this command is standard output of this command in the find output file, find out out or PhD or see any file you can say.

So, it will be executed. Similarly, we want we can redirect error of this command is chose to the path and we can also output everything else. The pipe command is generally used to execute two commands simultaneously, along with another functionality where output of command one written on the left hand side of first command is provided as input to the second command. We can use less command there are three more commands we learned here, the list command which is used to display input one page at a time. We can view any on one page at a time. So, in the in this command last line on the left hand side, the ls command, which is used to list shell, or show them files and directories within a certain folder is used to show those files display those files.

But there are a huge number of files possibly that can reside inside any directory or folder. But we want to see only few on the screen. So just provide right this command ls the part of the directory and the argument for the LS Sep right after that five symbol then right less Come on le SS. This will execute our functionality. Similarly, we can send output via email by using the mail command. Suppose we want to make Something mail I string, email a string via the terminal, we can do so by just writing echo command, provide the string, you want to mail within the quotes, then write a pipe symbol, then write the mail command, provide the argument and the email id, it will email.

Similarly, we can simply simply print any string on a piece of paper using the printer when it is connected to your computer by using LPR command. So, the way if we want to print any string directly from the terminal, just simply write echo command, provide the string, place the pipe symbol and write LPR it will be sent to printer and printer will simply print the string on a piece of paper. Then you can use output and error combination wherever Or put an error could be combined with ampersand and directed as a symbol. Similarly as with earlier examples there is another option where we can redirect a standard error to standard output by just writing two directed arrow ampersand symbol and one. It is useful for sending all the offers through a pipe. And with a parenthesis, you can combine standard outputs of multiple programs like here we did for the calendar of 2007 and 2008.

You can also redirect to multiple targets using the T command. Where some operators could be could affect both a standard output. It is towards the command here. It is still a standard output of command one in filename, then pipe to command to a pipe company. too good to be five again to command three. So you can use multiple times the pipe operator to execute multiple commands simultaneously in a single line.

The format would be the input of the first command, sorry output out the first command is provided as input to the second, output of second command is provided as input to second, and third and so on. You can read edit a standard input from a file with a left hand side arrow symbol. Some commands can accept data redirection to standard input from a file. Simply write the syntax write the command for example we were here we are writing tr command providing the range A to Zed capital and is fall redirecting it to a bash profile. It will translate the uppercase characters in dot bash profile to lowercase the equivalent condition of writing the same could be which cat Come on provide the file name earlier and tr command later on after the file. We another powerful thing that we can do with shell scripting is loop shell scripts are very useful thing that could be used for Server Administration and working over the network.

So, let us understand with an example. Suppose you have multiple files. For example, you have to execute a C code on every computer kept in a lab. The lab contains consists of 50 computers, and you have the sole responsibility of installing 10 c scripts. The C programming language so how you can execute a script You have to manually copy the scripts on each computer via pendrive or over the network, and then manually execute a script on each computer, it would take a very long time and it will get tedious or you can keep it short by writing a shell script is storing it on the pendrive or any network distribution environment. provided all the C scripts, the C script part would be saved inside that pendrive.

And the shell script is executed remotely from for each computer. Or you can execute simply just double click on each script for each PC, and it will execute all the commands simultaneously. Your work is very reduced. But just you need to write a shell script that executes the GCC compiler. For a sale a script and so, is C script. And so, similarly you can perform my huge range of tasks.

Shell scripts are basically designed to provide multi line out execution of the same commands that are been executed on Linux terminal with system variables and other functionalities. So, here there is an example for for loop loops are used for reputation of tasks, which can be used in the example I provided you. The for loop is a widely used in programming languages like Python, C, Java and other languages. Here we are using the for loop for three strings. Here we have three strings Joe, Jane and Julie. And we have a user defined variable call the name it will serve In these three strings when the condition is true, the execution of the three lines followed by two are done.

So, what is done in the first line of after do an email address is stored in a variable called address and another string is stored in a message. And the third line executes the execute a string within with pipe where the message variable is echoed or displayed, the output is transferred to the email address and the email address is provided by the address very well. So it is a simple way of writing the email to Jane, Joe and Julie. The three persons with a day may have an email id like Jane at the rate example.com. Here you can write a gmail.com yahoo.com or Yahoo mix.com and any other email ID that you have. So this is what we learned today.

We will learn more about later. The pipes, a standard input and output. Keep practicing those concepts. Just simply write multiple commands. They allow you a greater functionalities. So keep learning and keep moving ahead.

We will learn more

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.