1 / 12

Agenda

Agenda. Introduction to Shell Scripts Purpose of Shell Scripts Types of Shells / Running Shells Creating Simple Shell Scripts: Creating Portable Shell Scripts Commenting Running Shell Scripts. Shell Scripts.

Télécharger la présentation

Agenda

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Agenda Introduction to Shell Scripts • Purpose of Shell Scripts • Types of Shells / Running Shells • Creating Simple Shell Scripts: • Creating Portable Shell Scripts • Commenting • Running Shell Scripts

  2. Shell Scripts • Unix Shell Scripts are simply files that contain Unix commands that can be run or “issued” as a command (program). • Purposes of using Shell Scripts: • Automate Repetitive Tasks (instead of manually issuing commands manually). • Create new commands or utilities (with specified arguments including options) to meet the system administrator’s needs.

  3. Types of Shells • The Shell is a command interpreter that allows the user or administrator to issue commands. • Since the development of time, many shells have been created which provide features for the user or administrator. • Although this course concentrates on the bash shell, there are many other shells available.

  4. Types of Shells • Several Type of Shells are displayed below: • Bourne Shell • First shell created when Unix OS was created. Although considered to be “out-dated” all newer shells allow user to use Bourne Shell syntax thus making it a very “portable” (i.e. easily run on other shells)

  5. Types of Shells • C Shell • Shell that has many features for C programmers. • Korn Shell • Incorporates features from C Shell as well as improved mathematical processing features (eg. “built-in functions”) that was not available with Bourne Shell. Common shell used for programmers in Unix OS. The Linux equivalent of the Korn Shell is the “Z Shell”.

  6. Types of Shells • Bash Shell • Bash Shell is an acronym for “Bourne-again Shell” (a little “techie” humour). This shell is considered to encapsulate all of the best features of the Bourne, C, and Korn Shells. • Also, the Bash Shell is considered to be a “user-friendly” command interpreter with more intuitive command editing capabilities (such as up-arrow for displaying previously-issued commands)

  7. Running Shells • Although when using Tux, the Bash Shell is the default shell when you log onto your account, you can run many of the above-mentioned shells. (if in doubt, use the which command to locate pathname of shell). • ShellPathnameBash /usr/bin/bashKorn /usr/bin/kshand/or /usr/bin/zshC /usr/bin/cshBourne /usr/bin/sh

  8. Creating Portable Shell Scripts • One common problem when creating and running shell scripts is what happens if the type of shell that shell script was “designed-for” is not available on the operating system? • The next screen shows a technique to instruct the shell script to run in a “specified” shell or do not run if shell is not present. • This technique is called creating a portable shell script (eg. portable Bash shell script, portable C shell script, portable Korn shell script, etc…)

  9. Creating Portable Shell Scripts • On the first line of the shell script, you can choose which shell in which to run the script: • First Line Shell#!/bin/bash Bash (in Phobos #!/bin/bsh)#!/bin/ksh Korn#!/bin/csh C#!/bin/zsh Z#!/bin/sh Warning: # must be located in first column of first line and ! Must be located in second column of first line immediately followed by correct pathname or shell is run in “default” shell!

  10. Commenting Shell Scripts • It is a good idea to provide comments near the top of your shell script and comments throughout your shell script to help explain what the shell script does. • Remember: You may post this shell script on the Internet for others to use, or you may no longer be in charge of the shell script, so others need to view comments to quickly understand how shell scripts works.

  11. Commenting Shell Scripts • A comment is a hash symbol # • Any text after the hash symbol # is ignored by the shell for the remainder of the line.Examples:# This shell script does…mkdir mydir # Command to create directory “mydir” • If the command #! to specify which shell to run shell script in is not contained in first and second columns of first line respectively, the # is treated by shell like a comment and shell script is run in “default” shell! Shell ignores text

  12. Running Shell Scripts • There are two methods of running shell scripts: • Type the shell type with the name of the shell script as an argumenteg. bash script-name • Type the name of the shell script. This requires that the shell script file has at least read and execute permissions.Eg. script-name

More Related