Linux Shell Script Tutorial (1 of 2) [17/08/2001 17.42.10]
A pipe is nothing but a temporary storage place where the output of one command is stored and then passed as the input for second command. Pipes are used to run more than two commands ( Multiple commands) from same command line. Syntax: command1 | command2 Command using Pips Meaning or Use of Pipes $ ls | more Here the output of ls command is given as input to more command So that output is printed one screen full page at a time $ who | sort Here output of who command is given as input to sort command So that it will print sorted list of users $ who | wc -l Here output of who command is given as input to wc command So that it will number of user who logon to system $ ls -l | wc -l Here output of ls command is given as input to wc command So that it will print number of files in current directory. $ who | grep raju Here output of who command is given as input to grep command So that it will print if particular user name if he is logon or nothing is printed ( To see for particular user logon) Filter If a Linux command accepts its input from the standard input and produces its output on standard output is know as a filter. A filter performs some kind of process on the input and gives output. For e.g.. Suppose we have file called 'hotel.txt' with 100 lines data, And from 'hotel.txt' we would like to print contains from line number 20 to line number 30 and store this result to file called 'hlist' then give command $ tail +20 < hotel.txt | head -n30 >hlist Here head is filter which takes its input from tail command (tail command start selecting from line number 20 of given file i.e. hotel.txt) and passes this lines to input to head, whose output is redirected to 'hlist' file. © 1998-2000 FreeOS.com (I) Pvt. Ltd. All rights reserved. Linux Shell Script Tutorial (2 of 2) [17/08/2001 17.42.10]
Introduction to Shell Programming Shell program is series of Linux commands. Shell script is just like batch file is MS-DOS but have more power than the MS-DOS batch file. Shell script can take input from user, file and output them on screen. Useful to create our own commands that can save our lots of time and to automate some task of day today life. Variables in Linux Sometimes to process our data/information, it must be kept in computers RAM memory. RAM memory is divided into small locations, and each location had unique number called memory location/address, which is used to hold our data. Programmer can give a unique name to this memory location/address called memory variable or variable (Its a named storage location that may take different values, but only one at a time). In Linux, there are two types of variable 1) System variables - Created and maintained by Linux itself. This type of variable defined in CAPITAL LETTERS.
You've reached the end of your free preview.
Want to read all 46 pages?
- Spring '12
- Shell, Shell script, linux shell script