Practical Exercise: 4 (Standard I/O and Pipes)

Red Hat Linux Essentials Shortcuts, Variables, Shell Scripting, Standard I/O and Pipes
12 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.64
List Price:  €65.30
You save:  €18.66
£39.89
List Price:  £55.85
You save:  £15.96
CA$68.25
List Price:  CA$95.55
You save:  CA$27.30
A$76.15
List Price:  A$106.62
You save:  A$30.46
S$67.98
List Price:  S$95.18
You save:  S$27.19
HK$391.26
List Price:  HK$547.80
You save:  HK$156.53
CHF 45.56
List Price:  CHF 63.79
You save:  CHF 18.23
NOK kr549.77
List Price:  NOK kr769.72
You save:  NOK kr219.95
DKK kr347.88
List Price:  DKK kr487.07
You save:  DKK kr139.18
NZ$83.68
List Price:  NZ$117.16
You save:  NZ$33.47
د.إ183.60
List Price:  د.إ257.06
You save:  د.إ73.45
৳5,493.12
List Price:  ৳7,690.80
You save:  ৳2,197.68
₹4,172.34
List Price:  ₹5,841.61
You save:  ₹1,669.27
RM238.42
List Price:  RM333.81
You save:  RM95.39
₦66,243.24
List Price:  ₦92,745.84
You save:  ₦26,502.60
₨13,934.07
List Price:  ₨19,508.81
You save:  ₨5,574.74
฿1,850.39
List Price:  ฿2,590.69
You save:  ฿740.30
₺1,617.84
List Price:  ₺2,265.11
You save:  ₺647.26
B$255.79
List Price:  B$358.13
You save:  B$102.34
R936.97
List Price:  R1,311.83
You save:  R374.86
Лв91.24
List Price:  Лв127.74
You save:  Лв36.50
₩68,826.74
List Price:  ₩96,362.95
You save:  ₩27,536.20
₪188.13
List Price:  ₪263.40
You save:  ₪75.26
₱2,884.49
List Price:  ₱4,038.52
You save:  ₱1,154.02
¥7,792.89
List Price:  ¥10,910.67
You save:  ¥3,117.78
MX$856.20
List Price:  MX$1,198.75
You save:  MX$342.54
QR182.49
List Price:  QR255.51
You save:  QR73.01
P688.94
List Price:  P964.58
You save:  P275.63
KSh6,748.65
List Price:  KSh9,448.65
You save:  KSh2,700
E£2,392.02
List Price:  E£3,349.02
You save:  E£957
ብር2,872.52
List Price:  ብር4,021.76
You save:  ብር1,149.23
Kz41,694.65
List Price:  Kz58,375.85
You save:  Kz16,681.20
CLP$47,530.99
List Price:  CLP$66,547.19
You save:  CLP$19,016.20
CN¥362.03
List Price:  CN¥506.87
You save:  CN¥144.84
RD$2,934.22
List Price:  RD$4,108.14
You save:  RD$1,173.92
DA6,720.10
List Price:  DA9,408.68
You save:  DA2,688.58
FJ$112.74
List Price:  FJ$157.85
You save:  FJ$45.10
Q389.28
List Price:  Q545.03
You save:  Q155.74
GY$10,471.17
List Price:  GY$14,660.48
You save:  GY$4,189.30
ISK kr7,010.59
List Price:  ISK kr9,815.39
You save:  ISK kr2,804.80
DH505.57
List Price:  DH707.84
You save:  DH202.26
L884.78
List Price:  L1,238.76
You save:  L353.98
ден2,871.74
List Price:  ден4,020.67
You save:  ден1,148.92
MOP$403.59
List Price:  MOP$565.05
You save:  MOP$161.46
N$944.34
List Price:  N$1,322.15
You save:  N$377.81
C$1,841.99
List Price:  C$2,578.94
You save:  C$736.94
रु6,672.93
List Price:  रु9,342.64
You save:  रु2,669.70
S/188.02
List Price:  S/263.24
You save:  S/75.22
K193.20
List Price:  K270.50
You save:  K77.29
SAR187.49
List Price:  SAR262.50
You save:  SAR75.01
ZK1,326.34
List Price:  ZK1,856.98
You save:  ZK530.64
L232.07
List Price:  L324.92
You save:  L92.85
Kč1,174
List Price:  Kč1,643.69
You save:  Kč469.69
Ft18,283.73
List Price:  Ft25,598.69
You save:  Ft7,314.95
SEK kr545.79
List Price:  SEK kr764.15
You save:  SEK kr218.36
ARS$43,729
List Price:  ARS$61,224.11
You save:  ARS$17,495.10
Bs347.11
List Price:  Bs485.98
You save:  Bs138.87
COP$197,925.35
List Price:  COP$277,111.33
You save:  COP$79,185.97
₡25,432.40
List Price:  ₡35,607.40
You save:  ₡10,174.99
L1,235.97
List Price:  L1,730.46
You save:  L494.48
₲372,674.68
List Price:  ₲521,774.38
You save:  ₲149,099.69
$U1,931.55
List Price:  $U2,704.33
You save:  $U772.77
zł201.70
List Price:  zł282.40
You save:  zł80.69
Already have an account? Log In

Transcript

Hey friends and welcome back. Now in this part three is we are going to discuss standard input and output then I'm going to discuss piping and after all this thing I'm going to discuss a for loop insert script. So let's begin. So let's start with basic lands provides three IO channels two programs, one is STD in STD out and STD or let me tell you a more briefly that one of the most important feature of Linux, which is the ability to redirect a commands input or output or it can be arrows. In general, this allows the input for program to come from any source and the output to go any source which means that the when you execute one of the command of your command like LS or any other things, it is prism output on a terminal screen. This returning feature is that it will store all the content which is displaying on screen into a file.

Let me show you just open your terminal and Opera open terminal. Right LS let's take root example. Yeah, here you can see there are a lot of directories are showing on my terminal screen right now. Now I want to return this all country into a file. And for that, just write and use angle bracket and the angle bracket is facing towards the Atlas and read the any name for your file. Very well understood this all things and just sample dot txt Okay, now, open this file Sample exam food Spelling's we'll see run.

Okay? e x A and B you don't be XD as you can see on my terminal screen all the contents which we're displaying here non store in this example dot txt file okay in case actually by executing this command there is no error prompted, but in some case error must be there error may be there and for that purpose we will use STD Earth. Okay Aramis error font that you have to Firstly, let me as you know that we can't open a root folder without any permission, it will prompt an error on Yeah, cannot open air Crete to Permission denied. So this is a type of error. Okay for this to read. Just enter into a file you have to destroy it simply and it's true dot DSD wait yeah to putting down this error into this file you have the right to work so because two is for error and one is for a simple this all things or code which is displaying on terminal squint okay just right to here and put and press enter Now open this file now open this file and you will see that the error which we're displaying on terminal Skinner is displaying under this file cannot Open Directory with Permission denied okay to print this both thickness you also want to print this also and the error also suppose For that you can write instead of two you can write ampersand.

Actually this will not work, it will work, but actually there's only error in this command, there is no any output on screen positive or foe. So, using this combined or either using to command it will display a same content on your fight. So, let me show for this one. When you pass one parameter, it is print the error message because I didn't know put it to here. Now when I will open this file, it is empty because there is no and positive output for this Come on. I hope you are understanding what I want to say that let me revise one more time.

One four is a simple pause to output to four is for your errors and at this ampersand is for both your About put on your terminal skin and as well as your error also. So this is all about STD all UT. In short we can set a standard output. And now I'm going to discuss another symbol. This is an angle symbols facing toward this command if we use two angle braces then see what will happen right firstly I'm going to create a simple thing. Hi.

Let me get into now as you can see hi guys Printed here as this the equal height and the string is saved into the filename error dot txt and the uses of double angle brackets is that it will just append the content with your previous content is this double highest there. But if you not use double bracket and just write anything here, and then it will overwrite your content. As you can see, our new content is there, it overwritten this previous content. So this is all about our new symbol double angle bracket, which is used for appending purposes to concatenate your older data with new data. Okay, now the next thing which I am going to discuss Because that is piping for piping you have to use a pipe symbol and this pipe symbol is that it connects multiple commands together means you can execute multiple commands at a time.

So let me show you a simple example for that right LS root by using this command it will print all the directories now I'm going to use our pipe here and after pipe write t execute our another command and write the any file in list dot txt. Now you can see firstly it is acute this command as you can see here, because this being on my screen and after that, and after that The most important point is that that all output of this command is going to be a input of this command. As you can see now when I will going to open this list dot txt and you will see that all the content which we're displaying on my here is saved under this fight. This is all about piping. here if you can execute multiple commands at a time and as well as your previous commands or put will pita another commands input.

This is very important to note it out. And another thing last thing which I'm going to discuss in this particular series is that for loop in your bass strip, which I left on my previous video, so for that, firstly, open your G return, a simple graphical text editor had discussed earlier on my videos, then Dr. Shi bang, come on. This exclamation mark bin, bash. This you can cause to ban and after that just write simple for loop for in 1234 and write do then write equal equals and then dollar simple represent to display our content at large just right done. Now save this file, because it is a shell script save this file. Like for example, now this time I write a query for that example.sh ss for says script.

Okay, now, just write sh Yeah, you can see 1234 Certain hair. Actually what happened here is that for we we specify some value 1234 and two is starting point and 10 is our ending point for this follow, and it is painting a common spring, bending all the V value from here four v equal to one printed then comes to here 234. Right and with this sequence, it just passed here, done and all the work is done. Now, I'm going to do some changes in my, this example.ss route, just instead of V in 1234. You can also write like that one dot. Okay, I'm just going to take the 10 I'll save this file and run this file.

Now you can see this and this step printed a number sequence from one to 10 I hope you understand how to use for loop in bash script the simple stripe for in a slice it and V in one to 10 It's a sequence and this is starting with NC program I hope you are familiar with C programming and for loop you just write for i equals zero and so on. And then you start with curly opening curly braces and end up your closing curly braces syndrome is in here and shelf our script is do is for pinpoint and Dennis for end point. Okay, so this is a simple example for executing of false script in bash shell. I hope you understand 10 this four step and in my next video, I'm going to discuss some more Features of Irish Red Hat Enterprise Linux support till now.

Keep practicing, keep learning and all the best

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.