2008 Bangkok, Thailand Scripting Tools, languages and the Shell intERLab at AIT Network Management Workshop March 11-15 – Bangkok, Thailand.

Slides:



Advertisements
Similar presentations
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Advertisements

Chapter Seven Unix Shell Environments1 System Programming UNIX Shell Environments.
More about Shells1-1 More about Shell  Shells (sh, csh, ksh) are m Command interpreters Process the commands you enter m High-level programming languages.
CS 497C – Introduction to UNIX Lecture 32: - Shell Programming Chin-Chih Chang
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Linux+ Guide to Linux Certification, Second Edition
Scripting Languages CS351 – Programming Paradigms.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files.
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Linux Commands LINUX COMMANDS.
1. This presentation covers :  User Interface Administration  Files System and Services Management 2.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – Shell Programming The activities of.
Shell Programming, or Scripting Shirley Moore CPS 5401 Fall August 29,
Nic Shulver, Scripts and Batch files Scripting in Windows and Linux What is scripting? What is it for? DOS/Windows batch files.
Welcome to CSE  Name: Di Cao   Classroom: DL357  Class Time: T 8:30am - 9:18am  Office.
UNIX command line. In this module you will learn: What is the computer shell What is the command line interface (or Terminal) What is the filesystem tree.
Introduction to Shell Script Programming
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
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.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Cmsc 312 Operating Systems. UNIX? DOS – PC? VAX/VMS - mainframe Unix – PC, workstation, mainframe 1970 bell Lab For computer scientist? Why popular? Free.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
GNU Compiler Collection (GCC) and GNU C compiler (gcc) tools used to compile programs in Linux.
CS 6560 Operating System Design Lecture 3:Tour of GNU/Linux.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
Linux+ Guide to Linux Certification, Third Edition
Shell Scripting AFNOG IX Rabat, Morocco May 2008.
CS465 - UNIX The Bourne Shell.
Shell Programming. Introducing UNIX Shells  Shell is also a programming language and provides various features like variables, branching, looping and.
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
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.
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.
Writing Scripts Hadi Otrok COEN 346.
CSC414 “Introduction to UNIX/ Linux” Lecture 5. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
Chapter Six Introduction to Shell Script Programming.
1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This.
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
Linux+ Guide to Linux Certification, Second Edition
Configuration your environment Many user-configurable Unix programs (such as your shell) read configuration files when they start up. These configuration.
1 Week 8 Creating Simple Shell Scripts. 2 Chapter Objectives  In this chapter, you will :  Learn how to create Shell Scripts  Commenting / Making Portable.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Linux Administration Working with the BASH Shell.
Introduction to Scripting Workshop February 23, 2016.
Agenda Customizing a Unix/Linux account Environment Introduction to Start-up Files (.bash_profile,.bashrc,.profile,.kshrc) Safe Methods for Changing Start-up.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
2008 Bangkok, Thailand Scripting Tools, languages and the Shell intERLab at AIT Network Management Workshop March – Bangkok, Thailand.
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
Unix Scripting Session 1 March 6, 2008.
Development Environment Basics
CIRC Winter Boot Camp 2017 Baowei Liu
Department of Computer Engineering
SUSE Linux Enterprise Desktop Administration
Shell Features CSCI N321 – System and Network Administration
CAP652 Lecture - Shell Programming
Scripting Tools, languages and the Shell intERLab at AIT
Introduction to UNIX.
Henning Schulzrinne Advanced Programming
LING 408/508: Computational Techniques for Linguists
The Linux Command Line Chapter 24
Chapter Four UNIX File Processing.
Shell Programming.
Linux Shell Script Programming
Lab 4: Introduction to Scripting
Introduction to Bash Programming, part 3
The Linux Command Line Chapter 24
Presentation transcript:

Bangkok, Thailand Scripting Tools, languages and the Shell intERLab at AIT Network Management Workshop March – Bangkok, Thailand Hervey Allen

Bangkok, Thailand Languages Interpreted bash/sh, Perl, PHP, Python, Ruby Compiled C, C++, Java

Bangkok, Thailand Tools sed:Stream EDitor awk:Pattern scanning & processing dc:Arbitrary precision calculator bc:Arbitrary precision calculator language. tr:Translate or delete characters grep:Print lines matching a pattern

Bangkok, Thailand The Shell (bash) ‏ export printenv ~/.bashrc ~/.profile /etc/profile /etc/bash.bashrc /etc/skel (in Ubuntu) ‏

Bangkok, Thailand The Shell cont. By default, on Ubuntu, we use the Bourne Again SHell, or BASH. The shell is your interface to the kernel. Programs use the shell to determine their environment. Your shell environment can be customized. We'll go over how it's configured in Ubuntu.

Bangkok, Thailand The Shell cont. Flow of bash execution at startup: Interactive login 1. /etc/profile 2. ~/.profile 3. ~/.bashrc This is true for Ubuntu. See “ man bash ” for standard startup sequence. We'll go through this now...

Bangkok, Thailand The Shell cont. Flow of bash execution at startup: Interactive shell, no login 1. /etc/bash.bashrc 2. ~/.bashrc Non-interactive startup, run a script 1. Script looks for variable BASH_ENV 2. If it is set and is a file bash does this: if [ -n "$BASH_ENV" ]; then. "$BASH_ENV"; fi

Bangkok, Thailand Using the Shell Command Line Interpreter or CLI To understand scripts let's practice a bit with the CLI. At the shell prompt try: # cd; echo “Hello, World” > test.txt; cp test.txt test.txt.bak; vi test.txt The above is all on one line. What happened? Now try this: # cp test.txt $( date +%F )test.txt

Bangkok, Thailand Using the Shell In a file Now create a new file and place the some of our previous command in it: # cd # vi newscript echo “Hello world” > hello.txt cp hello.txt hello.txt.bak cat hello.txt+hello.txt.bak > new.txt cat new.txt :wq

Bangkok, Thailand Using the Shell In a file Now we can execute those commands in the order in which they appear in the file by doing this: # bash newscript # sh newscript #. newscript

Bangkok, Thailand Using the Shell As a shell script Now we can take the last step and start to create self-contained scripts that run on their own. We'll need to do two things: 1. Specify the CLI to use, and 2. Make our file executable

Bangkok, Thailand The “Shebang” To specify that a file is to become a shell script you specify the interpreter like this at the very start of the file: #!/bin/sh or #!/bin/bash etc... This is known as the “Shebang” (#!).

Bangkok, Thailand What's Next? Now let's create a very simple shell script. This will simply echo back what you enter on the command line: #!/bin/sh echo $1 Enter this in a file new.sh, then do: # chmod 755 new.sh

Bangkok, Thailand Run your script To run the script do: #./new.sh text #./new.sh “text with spaces...” Try updating the script to echo two, or more separated items on the command line.

Bangkok, Thailand When Not to Use A long'ish list... Resource-intensive tasks, especially where speed is a factor (sorting, hashing, etc.) ‏ Procedures involving heavy-duty math operations, especially floating point arithmetic arbitrary precision calculations, or complex numbers Cross-platform portability required Complex applications, where structured programming is a necessity (need type-checking of variables, function prototypes, etc.) ‏ Project consists of subcomponents with interlocking dependencies Extensive file operations required (Bash is limited to serial file access, and that only in a particularly clumsy and inefficient line-by-line fashion) ‏ Need native support for multi-dimensional arrays or data structures, such as linked lists or trees Need to generate or manipulate graphics or GUIs Need direct access to system hardware or port or socket I/O

Bangkok, Thailand Resources The books you received in class: Classic Shell Scripting The Bash Cookbook The on-line Advanced Bash Scripting Guide, available at: