Shell Scripting Tutorial – 3

Hello.

I am Aaditya Purani. I would be presenting tutorial 3 on Shell Scripting Tutorial

It’s common in Linux to pipe a series of simple, single purpose commands together to create a larger solution tailored to our exact needs. The ability to do this is one of the real strenghs of Linux. It turns out that we can easily accommodate this mechanism with our scripts also. By doing so we can create scripts that act as filters to modify data in specific ways for us.

Bash accomodates piping and redirection by way of special files. Each process gets it’s own set of files (one for STDIN, STDOUT and STDERR respectively) and they are linked when piping or redirection is invoked. Each process gets the following files:

  • STDIN – /proc/<processID>/fd/0
  • STDOUT – /proc/<processID>/fd/1
  • STDERR – /proc/<processID>/fd/2

To make life more convenient the system creates some shortcuts for us:

  • STDIN – /dev/stdin or /proc/self/fd/0
  • STDOUT – /dev/stdout or /proc/self/fd/1
  • STDERR – /dev/stderr or /proc/self/fd/2

fd in the paths above stands for file descriptor.

 

Code:

#!/bin/sh

while read line
do
echo “$line”;

done < “${1:-/dev/stdin}”

So thanks for Reading a video tut is here: https://youtu.be/ohWlP8d_uN8

Please contact me  : https://facebook.com/aaditya.purani.1

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s