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

Slides:



Advertisements
Similar presentations
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Advertisements

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.
Prof. R. Willingale Department of Physics and Astronomy 2nd Year C+R 2 nd Year C and R Workshop Part of module PA2930 – 2.5 credits Venue: Computer terminal.
Linux Commands LINUX COMMANDS.
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.
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.
2008 Bangkok, Thailand Scripting Tools, languages and the Shell intERLab at AIT Network Management Workshop March – Bangkok, Thailand.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
Chapter 6: Shell Programming
An Introduction to Unix Shell Scripting
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.
EMT 2390L Lecture 8 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
Shell Scripting AFNOG IX Rabat, Morocco May 2008.
#!/bin/sh echo Hello World cat Firstshellscript.sh Firstshellscript.sh.
Shell Programming. Introducing UNIX Shells  Shell is also a programming language and provides various features like variables, branching, looping and.
Chapter 2: Linux & POSIX “She sells bash shells by the C shore”
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.
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.
Configuration your environment Many user-configurable Unix programs (such as your shell) read configuration files when they start up. These configuration.
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
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/9/2006 Lecture 6 – String Processing.
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
EE516: Embedded Software Project 1
Introduction to Perl: Practical extraction and report language
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
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
Topics Introduction Hardware and Software How Computers Store Data
CAP652 Lecture - Shell Programming
The Linux Operating System
Scripting Tools, languages and the Shell intERLab at AIT
CSE 303 Concepts and Tools for Software Development
Introduction to UNIX.
Henning Schulzrinne Advanced Programming
LING 408/508: Computational Techniques for Linguists
CSC 140: Introduction to IT
The Linux Command Line Chapter 24
Chapter Four UNIX File Processing.
Shell Programming.
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
Lab 4: Introduction to Scripting
Lab 7 Shell Script Reference:
Linux Commands LINUX COMMANDS.
Introduction to Bash Programming, part 3
Bash Scripting CS 580U - Fall 2018.
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

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: