• Save
Unix And Shell Scripting
Upcoming SlideShare
Loading in...5
×
 

Unix And Shell Scripting

on

  • 6,756 views

Understanding Unix And Shell Scripting.

Understanding Unix And Shell Scripting.

Statistics

Views

Total Views
6,756
Views on SlideShare
6,526
Embed Views
230

Actions

Likes
20
Downloads
0
Comments
4

6 Embeds 230

http://www.techgig.com 193
http://www.slideshare.net 24
http://smontero.edumoot.com 7
http://www.linkedin.com 3
https://www.linkedin.com 2
http://kupluk2.blogspot.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Hi Malik,



    Presetation was very good, Shall I get a copy of above presentation if possible?

    my mail id is 'srinig20@gmail.com'



    Regards,

    Srini
    Are you sure you want to
    Your message goes here
    Processing…
  • Good Presentation! it's useful one for beginners of unix & shell
    Are you sure you want to
    Your message goes here
    Processing…
  • Unix And Shell Scripting
    Are you sure you want to
    Your message goes here
    Processing…
  • best one
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Unix And Shell Scripting Unix And Shell Scripting Presentation Transcript

  • Unix & Shell Scripting Presenter: Jaibeer Malik August 6, 2004
  • Agenda
    • Objectives
    • UNIX
    • Shell Scripting
    • Questions
    • Feedback
  • Session Objectives
    • Understand the basics of Unix Operating Environment
    • Understand the basics of Shell Scripting
  • Unix History
    • History of the Unix Operating System:
    • - Beginning at AT&T Bell Laboratories
    • - Kenneth Thompson
    • - Dennis Ritchie
    • - Berkeley: The Second School
    • - BSD UNIX
    • - Stallman and Torvalds
    • - GNU and LINUX
  • Unix Why???
    • There are only two kind of people
    • who understand 0 1 and who don’t understand
    • 01010101010101010101010101010101010101010101010101010
    • The features that made UNIX a hit from the start are:
      • Multitasking capability
      • Multi-user capability
      • Portability
      • UNIX programs
      • Library of application software
  • ARCHITECTURE
  • ARCHITECHTURE
    • The UNIX system is functionally organized at three levels:
      • The kernel, which schedules tasks and manages storage;
      • The shell, which connects and interprets users' commands, calls programs from memory, and executes them; and
      • The tools and applications that offer additional functionality to the operating system
  • Solaris File System Tree
  •  
  • Navigating The File System
    • pwd: Checking your Current Directory
    • cd: Changing Directory
    • mkdir: Making Directories
    • rmdir: Removing Directories
    • ls: Listing Files
  • General-Purpose Utilities
    • banner: Display a Blown-up Message
    • cal: The Calendar
    • date: Display the System Date
    • who: Login Details
    • tty: Knowing Your Terminal
    • man <command>: Displays help on <command>
    • apropos <keyword>:locates commands by keyword lookup
    • whatis <command>: Brief command description
  •  
  • Handling Files
    • cat: Displaying and Creating Files
    • cp: Copying a File
    • rm: Deleting Files
    • mv: Renaming Files
    • more: Paging Output
    • lp: Printing a File
    • file: Know the file types
    • wc: Line and Word and character counting
    • split: Splitting a File into Multiple Files
    • cmp: Comparing two files
  • File Attributes
    • ls –l: listing File Attributes
    • ls –d: Listing Directory Attributes
    • stat: Display File Permissions
    • chmod: Changing File Permissions
    • chown: Changing Ownership
    • chgrp: Changing Group
    • chsh: Changing Shell
    • ln: Links
    • umask: Define Defaults File Permissions for a User
  • The Environment
    • env: Displays Environment Properties
    • .profile: The Script Executed During Login Time
    • PWD: Know your Current Directory
    • HISTSIZE: Define History Size
    • LOGNAME: Login Name
    • SHELL: Your Default Shell
    • HOME: Define Home Directory
    • PATH: Declare Path
    • MAIL: Declare Mail Directory Path
    • alias: Define short-hand names for commands
  • The Process
    • ps: Process Status
    • <command> &: To run a process in Background
    • bg: To run a process in Background
    • fg: To run a process in Foreground
    • kill: Premature Termination of a Process
    • nice: job execution with low Priority
    • at and batch: Execute Later
    • cron: Running jobs Periodically
  • Communication And Electronic Mail
    • write: Two-way Communication
    • mesg: Your Willingness to Talk
    • talk: Splits the screen into two windows for chatting
    • mail: The mailer
    • news: To read news messages
    • elm: A screen-oriented mail handler
    • pine: Another mail program
    • finger: Details of Users
  • Networking
    • telnet: Remote Login
    • ftp: File Transfer (protocol)
    • rlogin: Remote Login Without Password
    • rcp: Remote File Copying
  • System Administration
    • useradd: Adding Users
    • /etc/passwd: User Information
    • /etc/shadow: Encrypted Passwords
    • userdel: Removing Users
    • fsck: File System Checking
    • df: Checking disk size
    • du: Checking file size
    • groupadd: Adding Group
    • groupdel: Deleting Group
    • groupmod: Modifying Group
  • The Shell
    • The following table shows the default system prompt and superuser prompt for the C shell, Bourne shell, and Korn shell.
  • Shell Scripting
    • A universal convention is that the extension .sh be used for shell scripts (or shell programs or shell procedures ).
    • The scripts can be executed in two ways:
    • $ chmod +x <filename.sh>
    • $ sh <filename.sh>
    • read: For taking input from the user
    • Example: $ cat example1.sh
    • #First Simple Example to print the standard input from the user to the standard output.
    • echo “Enter Your Name: “
    • read name
    • echo “Your name is: $name”
  • Shell Scripting (Contd..)
    • When arguments are specified with a shell procedure, they are assigned to certain special “variables” or rather positional parameters.
    • $1,$2,etc. The positional Parameters
    • $* Complete set of positional parameters as a single string
    • $# Number of arguments specified in command line
    • $0 Name of executed command
    • $? Exit status of the last command
    • $! PID of last command
  • Shell Scripting (Contd..)
    • Example: $ cat example2.sh
    • #Example to print the standard input from the user to the standard output using positional parameters.
    • echo “Program: $0
    • The Number of Arguments Specified is $#
    • The Arguments are $*”
    • echo “Your Name: $1 Your Extension Number: $2”
    • Example: $ example2.sh Jai 5630
    • Program: example2.sh
    • The Number of Arguments Specified is 2
    • The Arguments are Jai 5630
    • Your Name: Jai
    • Your Extension Number: 5630
  • Shell Programming (Contd..)
    • The && operator delimits two commands; the second command is executed only when the first succeeds.
    • The || operator delimits two commands; the second command is executed only when the first fails.
    • The exit statement is used to prematurely terminate a program.
    • The if Conditional
    • if condition is true
    • then
    • execute commands
    • else
    • execute commands
    • fi
  • Shell Scripting (Contd..)
    • Relational Operators
    • -eq Equal to
    • -neq Not equal to
    • -gt greater than
    • -ge greater than or equal to
    • -lt less than
    • -le less than or equal to
    • test uses certain operators to evaluate the condition on its right, and returns either a true or false
    • test $x –eq $y or [$x –eq $y]
    • String tests used by test
    • -n stg true if string stg is not a null string
    • -z stg true is string stg is a null string
    • s1 = s2 true if string s1=s2
    • s1! = s2 true if string s1 is not equal to s2
    • stg true if string stg is assigned and not null
  • Shell Scripting (Contd..)
    • File-related tests with test
    • -e file true if file exists
    • -f file true if file exists and is a regular file
    • -r file true if file exists and is a redable
    • -w file true if file exists and is a writable
    • -x file true if file exists and is a executable
    • -d file true if file exists and is a directory
    • -s file true if file exists and has a size greater than zero
  • Shell Scripting (Contd..)
    • The case conditional
    • case expression in
    • pattern1) execute commands;;
    • pattern2) execute commands;;
    • pattern3) execute commands;;
    • ……
    • esac
    • The while loop
    • while condition is true
    • do
    • execute commands
    • done
  • Shell Scripting (Contd..)
    • The for loop
    • for variable in list
    • do
    • execute commands
    • done
    • Example:
    • $ for x in 1 2 4 5 #list has 4 strings
    • do
    • echo “ The value of x is $x”
    • done
    • The value of x is 1
    • The value of x is 2
    • The value of x is 4
    • The value of x is 5
  • Shell Scripting (Contd..)
    • The here document symbol (<<) is used sometimes when we need to place the data inside the script.
    • The here document symbol (<<) is followed by the data and a delimiter.
    • shift transfers the contents of a positional parameter to its immediate lower numbered one.
    • When set –x is used inside a script, it echoes each statement on the terminal, preceded by a + as it is executed.
  • Example
    • bash-2.03$ cat example3.sh
    • IFS=&quot;|&quot;
    • while echo &quot;Enter Department Code: &quot;
    • do read dcode
    • set -- `grep $dcode data`
    • case $# in
    • 3) echo &quot;Department name : $2 Emp-id of head of dept : $3&quot;
    • shift 3 ;;
    • *) echo &quot;Invalid Code&quot; ; continue
    • esac
    • done
    • bash-2.03$ cat data
    • 01|accounts|6213
    • 02|admin|5423
    • 03|marketing|6521
    • 04|personnel|2365
    • 05|production|9876
    • 06|sales|1006
  • Example (Contd…)
    • bash-2.03$ bash example4.sh
    • Enter Department Code: 99
    • Invalid Code
    • Enter Department Code: 01
    • Department name : accounts Emp-id of head of dept : 6213
    • Enter Department Code: 06
    • Department name : sales Emp-id of head of dept : 1006 Enter Department Code:
  • Questions
    • ?
  • ... Feedback…