LINUX programming 1. INDEX UNIT-III PPT SLIDES Srl. No. Module as per Session planner Lecture No. PPT Slide No. 1.Problem solving approaches in Unix,Using.

Slides:



Advertisements
Similar presentations
CS 497C – Introduction to UNIX Lecture 32: - Shell Programming Chin-Chih Chang
Advertisements

CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Josh Goodwin
Linux+ Guide to Linux Certification, Second Edition
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
CS 497C – Introduction to UNIX Lecture 21: - The Shell Chin-Chih Chang
Information Networking Security and Assurance Lab National Chung Cheng University 1 What Linux is? Free Unix Like Open Source Network operating system.
The UNIX Shells 1. What is a Unix shell? 2. A few common shells in the Unix & Linux. A. Bourne shell B. Korn shell C. C shell D. Bash-the default shell.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Shell Programming 1. Understanding Unix shell programming language: A. It has features of high-level languages. B. Convenient to do the programming. C.
Introduction to Unix – CS 21 Lecture 5. Lecture Overview Lab Review Useful commands that will illustrate today’s lecture Streams of input and output File.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE1 Unix Comp-145 C HAPTER 2.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – Shell Programming The activities of.
3 File Processing Mauro Jaskelioff. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell The Shell The agency that.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
1 Shell Programming – Extra Slides. 2 Counting the number of lines in a file #!/bin/sh #countLines1 filename=$1#Should check if arguments are given count=0.
Advanced UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Shrinivas R. Mangalwede, GIT, Belgaum UNIX and Shell Programming (06CS36) Unit 3 Shrinivas R. Mangalwede Department of Computer Science and Engineering.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Unix Shells Based on Glass & Abels’ Book CS240 Computer Science II.
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
Shells. A program that is an interface between a user at a terminal and the computers resouces ▫The terminal may be real or an emulator The shell is.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
CS240 Computer Science II Introduction the Unix File System and File Related Utilities Based on “UNIX for Programmers and Users” by G.Class and K. Ables.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Essential Shell Programming by Prof. Shylaja S S Head of the Dept. Dept. of Information Science & Engineering, P.E.S Institute of Technology, Bangalore
Writing Shell Scripts ─ part 3 CSE 2031 Fall October 2015.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
Shell Programming. Creating Shell Scripts: Some Basic Principles A script name is arbitrary. Choose names that make it easy to quickly identify file function.
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
I/O and Redirection. Standard I/O u Standard Output (stdout) –default place to which programs write u Standard Input (stdin) –default place from which.
LINUX programming UNIT-2 1. INDEX UNIT-IV PPT SLIDES Srl. No. Module as per Session planner Lecture No. PPT Slide No. 1.Working with Bourne shell L1 1-2.
Operating Systems Lecture 10. Agenda for Today Review of previous lecture Input, output, and error redirection in UNIX/Linux FIFOs in UNIX/Linux Use of.
Introduction to Programming Using C An Introduction to Operating Systems.
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
THE BOURNE SHELL. Shell : the agency that sits between the user and the UNIX system. The BOURNE SHELL named after its founder Steve Bourne, is one of.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
CSCI 330 UNIX and Network Programming Unit III Shell, Part 1.
Introduction to Unix (CA263) Command File By Tariq Ibn Aziz.
Linux+ Guide to Linux Certification, Second Edition
Agenda The Bourne Shell – Part I Redirection ( >, >>,
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Linux Administration Working with the BASH Shell.
Shells.
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
By Jonathan Rinfret CREATING A BASH SCRIPT By Jonathan Rinfret
Unix Operating System (Week Two)
INTRODUCTION TO UNIX: The Shell Command Interface
Writing Shell Scripts ─ part 3
A Practical Guide to Linux® Commands, Editors, and Shell Programming
Chapter Four UNIX File Processing.
Linux Shell Script Programming
UNIX and Shell Programming (06CS36)
Chapter 3 The UNIX Shells
CSC 4630 Meeting 4 January 29, 2007.
Essential Shell Programming
Presentation transcript:

LINUX programming 1

INDEX UNIT-III PPT SLIDES Srl. No. Module as per Session planner Lecture No. PPT Slide No. 1.Problem solving approaches in Unix,Using Single command L1 2 1.Using compound command L shell scripts L C programs,Building own command library of programs L Revision 2

Problem solving approaches in UNIX Using single command: If only one command is used for solving a problem then the command is known as single Unix command for solving a problem. Eg: $mv file1 file2 $cd /usr/bin This is the simplest approach for solving a problem. 3

Problem solving approaches in UNIX Using compound commands: When a single command is not sufficient to solve a problem, try to join the commands together. Two approaches for this are: Redirection Piping 4

Redirection: Unix commands are built-up in such a way that they can take the input from the keyboard, often called standard input and usually send their output to the screen, often called standard output. Commands also send error information to the screen. We can also change these defaults by using a process called redirection. 5

There are three standard files. The shell sets up these three standard files and attaches them to user terminal at the time of logging in. Standard i/p ----default source is the keyboard. Standard o/p ----default source is the terminal. Standard error ----default source is the terminal. 6

Standard i/p: It has three sources The keyboard, default source A file using redirection with < Another program using a pipeline. Eg: $wc or $wc file1 $wc < file1 or $cat file1 | wc 7

Standard o/p: It has 3 destinations. The terminal, default source A file using redirection with >, >> Another program using a pipeline. Using the symbols >,>> u can redirect the o/p of a command to a file. Eg: $cat file1 $cat file1>file2 $who | newfile 8

Standard Error: When u enter an incorrect command or trying to open a non existing file, certain diagnostic messages show up on the screen. This is the standard error stream. Trying to cat a nonexistent file produces the error stream. $cat bab Cat: cannot open bab :no such file or directory 9

The standard error stream can also be redirected to a file. $cat bar 2> errorfile Here 2 is the file descriptor for standard error file. Each of the standard files has a number called a file descriptor, which is used for identification. 0—standard i/p 1---standard o/p 2---standard error 10

Pipes Standard I/p & standard o/p constitute two separate streams that can be individually manipulated by the shell. The shell connects these streams so that one command takes I /p from other using pipes. Who produces the list of users, to save this o/p in a file use $who > user.lst To count the no. of lines in this user.lst use $wc –l <user.lst Command Standard Output | Pipe Standard input Command 11

Instead of using 2 separate commands we can combine them using pipes. $who | wc –l Here who is said to be piped to wc. To count no. of files in current directory $ls | wc –l There’s no restriction on the no. of commands u can use a pipeline. 12

Shell scripts All the Unix commands can be entered in the command line itself. When a group of commands have to be executed regularly, they are better stored in a file. All such files are called shell scripts or shell programs. There’s no restriction on the extension of the file name, though it is helpful to use.sh as the extension. 13

The following shell script is a sequence of commands: $cat script.sh echo the date today is `date` echo ur shell is $SHELL echo ur home directory is $HOME U can use vi to create this script. To execute this script use $sh script.sh or $script.sh 14

Positional parameters: Shell script accept arguments in another manner-from the command line itself. This is the non interactive method of specifying the command line arguments. When the arguments are specified with a shell script, they are assigned to certain special variables-rather positional parameters. The first argument is read by the shell into the parameter $1, second argument into $2 and so on. 15

The various special parameters used in the script are $1—the first argument $2—the second argument $0—the name of the script $#--the no. of arguments $*--the complete set of positional parameters as a single string. 16

C programs C is the robust language & most of the Unix is written in c. C is a compiled language, i.e. u can use one of the system editor to write the program. Then submit this program to C compiler, then run the program. U can build C programs in Unix also. 17

Steps for writing a C program in UNIX: Use an editor such as vi, ex or ed to write the program. The file name of the program must end with.c in order to identify it as a C program by the compiler. Submit the file to C compiler using cc. Eg: $cc filename.c Run the program using $a.out 18