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
€48.02
List Price:  €67.23
You save:  €19.21
£39.14
List Price:  £54.79
You save:  £15.65
CA$71.63
List Price:  CA$100.29
You save:  CA$28.65
A$80.06
List Price:  A$112.09
You save:  A$32.03
S$67.51
List Price:  S$94.52
You save:  S$27.01
HK$388.46
List Price:  HK$543.88
You save:  HK$155.41
CHF 44.24
List Price:  CHF 61.94
You save:  CHF 17.70
NOK kr563.34
List Price:  NOK kr788.73
You save:  NOK kr225.38
DKK kr358.57
List Price:  DKK kr502.03
You save:  DKK kr143.46
NZ$88.43
List Price:  NZ$123.81
You save:  NZ$35.37
د.إ183.61
List Price:  د.إ257.07
You save:  د.إ73.45
৳5,964.32
List Price:  ৳8,350.53
You save:  ৳2,386.20
₹4,269.04
List Price:  ₹5,977
You save:  ₹1,707.95
RM224.30
List Price:  RM314.04
You save:  RM89.74
₦77,264.53
List Price:  ₦108,176.53
You save:  ₦30,911.99
₨13,894.99
List Price:  ₨19,454.09
You save:  ₨5,559.10
฿1,708.15
List Price:  ฿2,391.55
You save:  ฿683.40
₺1,759.41
List Price:  ₺2,463.31
You save:  ₺703.90
B$318.75
List Price:  B$446.27
You save:  B$127.52
R937.33
List Price:  R1,312.34
You save:  R375
Лв93.99
List Price:  Лв131.59
You save:  Лв37.60
₩72,848.40
List Price:  ₩101,993.60
You save:  ₩29,145.19
₪182.43
List Price:  ₪255.42
You save:  ₪72.98
₱2,932.41
List Price:  ₱4,105.61
You save:  ₱1,173.20
¥7,857.17
List Price:  ¥11,000.67
You save:  ¥3,143.49
MX$1,008
List Price:  MX$1,411.29
You save:  MX$403.28
QR181.52
List Price:  QR254.14
You save:  QR72.62
P693.18
List Price:  P970.50
You save:  P277.32
KSh6,450.70
List Price:  KSh9,031.50
You save:  KSh2,580.80
E£2,541.20
List Price:  E£3,557.88
You save:  E£1,016.68
ብር6,354.82
List Price:  ብር8,897.26
You save:  ብር2,542.43
Kz45,590.88
List Price:  Kz63,830.88
You save:  Kz18,240
CLP$49,454.60
List Price:  CLP$69,240.40
You save:  CLP$19,785.80
CN¥364.87
List Price:  CN¥510.85
You save:  CN¥145.98
RD$3,040.26
List Price:  RD$4,256.60
You save:  RD$1,216.34
DA6,753.71
List Price:  DA9,455.74
You save:  DA2,702.02
FJ$115.90
List Price:  FJ$162.28
You save:  FJ$46.37
Q384.44
List Price:  Q538.26
You save:  Q153.81
GY$10,442.13
List Price:  GY$14,619.81
You save:  GY$4,177.68
ISK kr6,976.10
List Price:  ISK kr9,767.10
You save:  ISK kr2,791
DH503.31
List Price:  DH704.68
You save:  DH201.36
L920.86
List Price:  L1,289.28
You save:  L368.41
ден2,954.07
List Price:  ден4,135.94
You save:  ден1,181.86
MOP$399.27
List Price:  MOP$559.01
You save:  MOP$159.74
N$928.04
List Price:  N$1,299.34
You save:  N$371.29
C$1,836.54
List Price:  C$2,571.30
You save:  C$734.76
रु6,797.51
List Price:  रु9,517.06
You save:  रु2,719.54
S/185.85
List Price:  S/260.20
You save:  S/74.35
K202.57
List Price:  K283.61
You save:  K81.04
SAR187.71
List Price:  SAR262.82
You save:  SAR75.10
ZK1,381.27
List Price:  ZK1,933.89
You save:  ZK552.61
L239.16
List Price:  L334.85
You save:  L95.68
Kč1,208.85
List Price:  Kč1,692.49
You save:  Kč483.63
Ft19,737.39
List Price:  Ft27,633.93
You save:  Ft7,896.53
SEK kr544
List Price:  SEK kr761.65
You save:  SEK kr217.64
ARS$51,344.11
List Price:  ARS$71,885.87
You save:  ARS$20,541.75
Bs344.88
List Price:  Bs482.86
You save:  Bs137.98
COP$220,596.26
List Price:  COP$308,852.42
You save:  COP$88,256.15
₡25,341.90
List Price:  ₡35,480.70
You save:  ₡10,138.79
L1,268.10
List Price:  L1,775.44
You save:  L507.34
₲389,249.85
List Price:  ₲544,980.94
You save:  ₲155,731.08
$U2,221.61
List Price:  $U3,110.44
You save:  $U888.82
zł204.67
List Price:  zł286.56
You save:  zł81.88
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.