UnixShells.pdf - CHAPTER III SHELL PROGRAMMING B Boufama University of Windsor Chapter III Shell Programming Introduction A Unix shell is a command


This preview shows page 1 - 9 out of 34 pages.

CHAPTER III: SHELL PROGRAMMING B. Boufama University of Windsor
Image of page 1
Chapter III: Shell Programming Introduction A Unix shell is a command interpreter that starts running as soon as you log on A shell command can be internal(built-in) : code is part of the shell or, external : code resides in a sperate binary file. Because the shell accepts command from the keyboard, it terminates when the special character CTR-D is entered. CTR-D triggers an EOF. B. Boufama 1
Image of page 2
Chapter III: Shell Programming Path and external commands For an external command, the shell searches for its file in the directories whose names are stored in the shell variable PATH . How to define the shell varibale PATH ? Example : PATH = ./ : /usr/bin : /bin the shell looks for the command in this order: 1. in ./ , the current directory, 2. in /usr/bin/, and finally in 3. /bin , i.e., your-home-directory/bin/ B. Boufama 2
Image of page 3
Chapter III: Shell Programming PATH can be modified, examples : PATH=$PATH: /new/bin/ PATH=/usr/local/bin:$PATH echo $PATH to display PATH contents it which an interesting command tp find opther commands. Examples: which bash, which gcc Note: PATH is intially set in shell start-up files, like /.profile, /etc/profile, /.cshrc, etc. B. Boufama 3
Image of page 4
Chapter III: Shell Programming Selecting a Shell Unix comes with a variety of shells, examples include Bourne again shell (Bash), C shell and korn shell. All shells are nomally located in /usr/bin/, they differ in their level of functionalities. Bourne Again shell : bash widely used, superset of Bourne shell sh . C shell : csh richer than sh , syntax to C. Korn shell : ksh derived from sh with more functions. B. Boufama 4
Image of page 5
Chapter III: Shell Programming Running a shell When a shell starts, it 1. reads special startup files (e.g., /etc/profile then /.profile for bash) that contain some initialization information, 2. displays a prompt and waits for user commands then, 3. the shell executes the user’s command and returns to step 2 unless the user has typed the characters CTR-D which will cause the shell to terminate. Note that a shell is invoked either automatically, at the login, or manually. B. Boufama 5
Image of page 6
Chapter III: Shell Programming Metacharacters These are special characters with special meanings : > : Output redirection E.g., ls > fileNames.txt < : Input redirection E.g., mailx [email protected] < letter.txt >> : Output redirection, appends to a file E.g., ls >> fileNames.txt * : filename Wild card, matches 0 or more characters E.g., rm *ps, delete all files ending with ’ps’. ? : filename Wild card, matches 1 character. E.g., rm *.? delete files with one character after ’.’ ls ?? list files/directories made up of 2 characters. B. Boufama 6
Image of page 7
Chapter III: Shell Programming command ‘ : command substitution, replaced by the command output. E.g. 1. echo The date of today is ‘date‘ E.g. 2. echo hello ls hello ls echo hello ‘ls‘ hello followed by the ls outputs.
Image of page 8
Image of page 9

You've reached the end of your free preview.

Want to read all 34 pages?

  • Fall '17
  • Stephenos

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes