INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

1 Introduction to UNIX Ke Liu
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
23-Jun-15Advanced Programming Spring 2002 bash Henning Schulzrinne Department of Computer Science Columbia University.
1 Basics of Linux On linux machine: Login at your home directory Open a “shell” or “terminal” or “xterm” workspace (4) On windows machine Intall linux.
Lecture 01CS311 – Operating Systems 1 1 CS311 – Lecture 01 Outline Course introduction Setting up your system Logging onto the servers at OSU with ssh.
1 UNIX essentials (hands-on) the directory tree running programs the shell (using the T-shell) → command line processing → special characters → command.
Introduction to Linux and Shell Scripting Jacob Chan.
Shell Script Examples.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
Linux Shell. 2 Linux Command-Line Interface ■ Linux shells: A shell is a command interpreter that allows you to type commands from the keyboard to interact.
Linux Commands LINUX COMMANDS.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
Nic Shulver, Scripts and Batch files Scripting in Windows and Linux What is scripting? What is it for? DOS/Windows batch files.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
CENT 305 Information Systems Security Linux Introduction.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
CS 6560 Operating System Design Lecture 3:Tour of GNU/Linux.
July 17, 2003Serguei A. Mokhov, 1 Shells and Shell Scripts COMP 444/5201 Revision 1.3 January 25, 2005.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
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.
Next Unix Topics Tuesday, 2/11 & 18/2014. Change Password (by 2/14/14) ssh to account on – faclinux.cse.ohio-state.edu – stdlinux.cse.ohio-state.edu passwd.
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.
INFO 320 Server Technology I Week 5 Shell environments and scripting 1INFO 320 week 5.
Writing Scripts Hadi Otrok COEN 346.
UNIX shell environments CS 2204 Class meeting 6 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Using UNIX Shell Scripts Michael Griffiths Corporate Information and Computing Services The University of Sheffield
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Introduction to Programming Using C An Introduction to Operating Systems.
CSC414 “Introduction to UNIX/ Linux” Lecture 5. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
CS252: Systems Programming Ninghui Li Slides by Prof. Gustavo Rodriguez-Rivera Topic 7: Unix Tools and Shell Scripts.
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.
Linux Commands C151 Multi-User Operating Systems.
THE UNIX SYSTEM Jan Recitation 2 Introduction to Networking.
Unix Advanced Shells Chapter 10. Unix Shells u Command Line Interpreter –once logged in, login gives control to a shell –it prompts for input, then parses,
Linux A practical introduction. 1)Background and Getting Started Linux is an operating system with multiple providers Red Hat/CentOS (our version) Ubuntu.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Learning Unix/Linux Based on slides from: Eric Bishop.
Using Linux Kaya Oğuz Room: 310.
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
CS 350 Lecture 3 UNIX/Linux Shells by İlker Korkmaz and Kaya Oğuz.
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
EE516: Embedded Software Project 1
CIRC Winter Boot Camp 2017 Baowei Liu
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Andy Wang Object Oriented Programming in C++ COP 3330
System Programming and administration CS 308
CAP652 Lecture - Shell Programming
Unix Shells.
Some Linux Commands.
The Linux Operating System
Shell Script Assignment 1.
Introduction to UNIX.
Introduction to Linux Week 0 - Thursday.
John Carelli, Instructor Kutztown University
Unix : Introduction and Commands
Andy Wang Object Oriented Programming in C++ COP 3330
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
Chapter 3 The UNIX Shells
Linux Commands LINUX COMMANDS.
Presentation transcript:

INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank

CONTENTS What is the SHELL?? Basic Commands Shell Scripting (Programming) Assignment & Test

What is the SHELL?? USERS Utils/ AppsSHELL OS (Kernel) Hardware

SHELL Cont’d It interfaces the OS and the Users: interprits and executes user typed commands GUI (Graphical User Interface): Windows, Mac OSX, Linux, IOS, Android CLI (Command Line Interface): bash, csh, zsh, command.com, etc

General Function of the SHELL The UNIX shell program interprets user commands, which are either directly entered by the user, or which can be read from a file called the Shell Script or Shell program. Shell scripts are interpreted, but not compiled. The shell reads commands from the script line per line and searches for those commands on the system, while a compiler converts a program into machine readable form, an executable file- which may then be used in a shell script. Apart from passing commands to the kernel, the main task of a shell is providing a user environment, which can be configured individually using shell resource configuration files.

Types of SHELL Just like the many languages known around the world, the UNIX system usually offers a variety of shell types..sh or Bourne again: the original shell still used on UNIX systems and in UNIX related environments. While this is not standard, it is still available on every linux system for compatibility with UNIX programs. Bash or Bourne Again Shell: the standard GNU shell intuitive and flexible. csh or C shell: the syntax of this resembles that of C programming. tcsh or TENEX C shell: this is a superset of the common C shell, enhancing user friendliness and speed. ksh or Korn shell: this is a superset of Bourne shell; with standard configuration. e.g /bin/sh /bin/bash /bin/csh /bin/ksh

Basic Commands % pwd % ls % ls -l % man ls % % pdbget.sh 4g8v % less 4g8v.pdb % df -h % free % ps ax % whoami % who % w % top % cd users/ % mkdir [your own ID] % mkdir [your ID] # for example % cd [your ID] % cp -r../newton/*. % ls –l % cd bash # for bash % ls -l *

* Directories % pwd (print working directory) /net/guest % mkdir work (make directory) % cd work % pwd /net/guest/work % cd /usr/bin % pwd % cd % pwd (change your home directory) /net/guest % rmdir work (remove directory) or ‘rm -r‘ (recursive rm)

* Listing files % ls /home (print working directory) % cd % ls % ls -a % ls -al % ls -tl % ls -tlr %

Listing Files Cont’d % cd users/newton/bash % ls -l total 236 -rwxrwxr-x 1 guest 2013winter 337 Jan 20 06:42 xyz.sh -rwxrwxr-x 1 guest 2013winter Jan 20 06:43 4g8v.pdb drwxrwxr-x 2 guest 2013winter 4096 Jan 21 06:12 work drwxrwxr-x 2 guest 2013winter Jan 21 11:00 T0736

* Viewing Files, less % cd /net/guest/users/newton/bash % cat 4g8v.pdb % less 4g8v.pdb * Symbolic Links % ln -s 4g8v.pdb my.pdb % ls -l % cat my.pdb % less my.pdb

* File Copy, Move (rename), remove % cd /net/guest/users/newton/bash % cp 4g8v.pdb test.pdb (copy) % ls -l % mkdir temp % mv test.pdb temp (move) % cd temp/ % rm test.pdb (remove) % cd../ % rm -r temp (recursive rm)

* Shells Bash Bourn Again Shell tcsh Turbo C-shell ksh, zsh, etc... % echo $SHELL (print your shell) % chsh (change your shell) * Filename Expansion % cd /net/guest/users/newton/bash/T0736 % ls b*.pdb % ls b0??.pdb % ls b00[12].pdb % ls b00[13].pdb % ls b00[1-3].pdb % ls *.{pdb,ent}

* Saving your output % cd /net/guest/users/newton/bash/T0736 % ls -al > output (redirection) % ls / > output % ls /net > output % ls /net/guest >> output (append) % ls test.pdb % ls test.pdb > messages (‘>’ does not redirect standard error) % ls test.pdb &> messages % ls b001.pdb test.pdb 1> message % ls b001.pdb test.pdb 2> message % ls b001.pdb test.pdb &> message

* Etc commands % who (who login?) % w % w | grep guest (show line with “newton” string) % finger guest (show user status) % free (show memory usage) % df (show disk usage) % ps (show process list) % ps ax (all process list with user id) % top (show process status) % man ls (manual page for “ls”) % find -name b001.pdb % find /net -name “*.sh” *

Editors... (for text editing) * Full featured editors in Linux/Unix % vi % emacs * Easy, simple editor for beginner % nano

Hello BIT II 2014 % cd work % nano bit.sh #!/bin/sh echo "Hello BIT II 2014!" % bash bit.sh # execution ( sh bit.sh ) Hello BIT II 2014! % ls -l bit.sh % chmod +x bit.sh # change file mode % ls -l bit.sh %./bit.sh # execution

Shell Scripting Variables Arithmetics Branches Loops Functions

Example (multi.sh) #!/bin/sh a=$1 if [ $a -lt 1 -o $a -gt 9 ]; then echo “The number is out of range [1,9]” exit fi echo "Multiplication Table for $a“ for i in do m=$[a * i] echo "$a x $i = $m" done bash interpreter variable and shell parameter branche print statement loop arithmetic

Variables * Their values are always stored as strings (default) * No need to declare a variable - Environmental variables % echo $SHELL % echo $HOME % echo $PATH % echo $USER - User defined variables % i=10 # no space % echo $i # $ for using variable % str=”Hello World” % echo $str

Quotes... %bash quotes.sh 1) Double quotes (partial quoting) % echo $HOME % str=“My home directory is $HOME” # double % echo $str My home directory is /net/guest 2) Single quotes (full quoting) % echo $HOME % str=‘My home directory is $HOME‘ # single % echo $str My home directory is $HOME

Quotes Cont’d 3) Back quotes (command substitution) % pwd/net/guest % str=`pwd` # or str=$(pwd) % echo “My home directory is $str” My home directory is /net/guest % cd T0736 # in the bash directory % ls b*.pdb # or ls b???.pdb % pdbs=`ls b*.pdb` % echo $pdbs

Arithmetics... Operators: + plus - minus * multiplication / division ** exponentiation % modulo Examples: % let a=10+2*7 # no space, but let a=( *7) % echo $a 24 % a=$((10+2*7)) # or a=$[10+2*7] % echo $a 24