COMELEC III - Bash unit 1
Upcoming SlideShare
Loading in...5
×
 

COMELEC III - Bash unit 1

on

  • 744 views

 

Statistics

Views

Total Views
744
Views on SlideShare
744
Embed Views
0

Actions

Likes
0
Downloads
14
Comments
0

0 Embeds 0

No embeds

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…
Post Comment
Edit your comment

COMELEC III - Bash unit 1 COMELEC III - Bash unit 1 Presentation Transcript

  • Linux Bourne Again Shell (BASh) Programming VSRivera IBM Learning Services Worldwide Certified Manual
  • Unit 1. Basic Shell Concepts
    • Objectives
      • Describe the Linux Shell
      • Use the Linux file system
      • Create a shell script
      • Use metacharacters and brace expansion
      • Use I/O redirection
      • Use pipes and tees
      • Group commands
      • Use Bash shell job control
      • Use command line recall and editing
  • Shells
    • User interface to linux
    • Command interpreter
    • Programming Language
    • Linux Shells
      • Bash V1 - bash
      • Public Domain Korn - ksh
      • Bourne/System V - ash
      • C Compatible - tcsh
  • Shells
    • Each shell has different features and syntax
    • GNU Bash adds features to the standard System V or Bourne Shell.
    • Bash was written by Free Software Foundation (FSF) as free software.
    • Bourne shell is the oldest shell written by Steven Bourne.
    • David G. Korn wrote the Korn Shell at AT&T’s Bell Labs (Lucent). It is more recent than other shells .
  • Directories
    • The file system comprises directories in a hierarchical structure
    • All Linux directories are contained in one, virtual, "unified filesystem“
    • Physical devices are mounted on mount points
      • Floppy disks
      • Hard disk partitions
      • CD-ROM drives
    • No drive letters like A:, C:, ...
  • File
    • Collection of data
    • A stream of characters or a byte stream
    • No structure is imposed on a file by the operating system
    • Directories and devices are known as “special files” – the operating system controls their use.
      • /dev/null
      • /home
  • File Names
    • Should be descriptive of the content
    • Should use only alphanumeric characters
      • UPPERCASE, lowercase, number,
      • . , @, - , _
    • Should not include embedded blanks
    • Should not contain shell metacharacters: *
      • ? > < / ; & ! [ ] | ' &quot; ( ) { }
  • File Names
    • Should not begin with + or - sign
    • Are case sensitive
    • Filenames starting with a . are hidden
    • The maximum number of characters for a filename is 255
    • Pathname length of 4095 characters
  • Shell Script
    • A readable text file which can be edited with a text editor
    • Anything that you can do from the shell prompt
    • A program containing:
      • System commands
      • Variable assignments
      • Flow control syntax
      • Shell commands
      • comments
  • Invoking Scripts
    • $ . prog
      • prog runs in current shell environment
    • bash prog
      • Run prog in a new shell
    • prog
      • Run in a new shell if prog is executable
    • exec prog
      • Run in a new shell to replace a current one
  • Metacharacters
    • Characters that have special meaning
      • Wildcard or filename expansion
      • Quoting
    • Characters that do not represent themselves
    • Shell processes metacharacters before executing a command
  • Wildcard metacharacters
    • Metacharacters that form patterns that are expanded into matching filenames from the current directory
      • * – match any number of any characters
      • ? – match any single character
      • [abc] – match a single character from a bracketed list
      • [!az] – match any single character except those listed
      • [a-z] – inclusive range for a list
    • Character equivalence classes can be used in place of range lists
      • [[:upper:]] – range list of uppercase classes
      • [[:lower:]] – all lower case letters
      • [[:digit:]] – digits
      • [[:space:]] – spacing characters: tab, space, etc..
  • Expansion examples
    • $ rm d*y
    • $ file script*
    • $ ls script[345]
    • $ touch ?a*
    • $ ls [st][ah]*
    • $ touch [^ab]*
    • $ touch [a-z]*t[0-9]
  • Quoting metacharacters
    • Stops normal shell metacharacter processing, including metacharacter expansion
      • To form strings
        • “ double quotes” group character into a string, and allow variable and command substitution. Everything between &quot; and &quot; is taken literally except $, `, “
  • Quoting metacharacters
      • To form literal strings
        • ‘ single quotes’ remove special meaning for the character within them. Everything between ' and ' is taken literally, except for another ‘.
      • For a literal character
        • character removes the special meaning of the character following the .
        • Where is nested inside double quotes, it only removes the special meaning of characters: , ‘, “, $.
  • Brace expansion
    • Bash allows an additional expansion facility
      • Brace ({}) expansion
      • $ ls *{1,2}
      • $ mkdir release_{src,doc}
      • $ cat {file1,file2,file3} > combined_file
      • $ cp file22.{txt,backup}
      • $ echo {a..z}
      • $ echo {0..3}
      • $ echo hi{DDD,BBB,CCC,AAA}there
      • $ ls {ch,app}?
    • Question?