Lab 4: Introduction to Scripting

Slides:



Advertisements
Similar presentations
CS 497C – Introduction to UNIX Lecture 32: - Shell Programming Chin-Chih Chang
Advertisements

CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
UNIX chapter 04 UNIX Shells Mr. Mohammad Smirat. Introduction The shell is the software that listens to commands typed in at the terminal and translates.
Basic linux shell commands and Makefiles. Log on to engsoft.rutgers.edu Open SSH Secure Shell – Quick Connect Hostname: engsoft.rutgers.edu Username/password:
How shell works Shell reads in input, parse & process it, the resulting string is taken to be argv[] and executed echo a  shell sees “ echo a ” echo gets.
CSc 352 Shell Scripts Saumya Debray Dept. of Computer Science
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Chapter 15 Introductory Bash Programming
Lecture Note 3: ASP Syntax.  ASP Syntax  ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source"
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.
Chapter 6: Shell Programming
An Introduction to Unix Shell Scripting
GNU Compiler Collection (GCC) and GNU C compiler (gcc) tools used to compile programs in Linux.
Scons Writing Solid Code Overview What is scons? scons Basics Other cools scons stuff Resources.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Linux Operations and Administration
Shell Scripting AFNOG IX Rabat, Morocco May 2008.
UNIX Commands. Why UNIX Commands Are Noninteractive Command may take input from the output of another command (filters). May be scheduled to run at specific.
CSC 352– Unix Programming, Spring 2015 March 2015 Shell Programming (Highlights only)
Getting started: Basics Outline: I.Connecting to cluster: ssh II.Connecting outside UCF firewall: VPN client III.Introduction to Linux IV.Intoduction to.
Bioinformatics Introduction to Perl. Introduction What is Perl Basic concepts in Perl syntax: – variables, strings, – Use of strict (explicit variables)
Guide to Linux Installation and Administration, 2e1 Chapter 11 Using Advanced Administration Techniques.
Writing Scripts Hadi Otrok COEN 346.
Data Display Debugger (DDD)
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Dr. Sajib Datta CSE Spring 2016 INTERMEDIATE PROGRAMMING.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 4 – Shell Variables, More Shell Scripts.
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Chapter 1: Introduction to Computers and Programming.
Linux Administration Working with the BASH Shell.
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
Discussion on mp1.
Agenda Introduction Computer Programs Python Variables Assignment
Exam #1 You will have exactly 30 Mins to complete the exam.
User-Written Functions
CIRC Winter Boot Camp 2017 Baowei Liu
CSE 374 Programming Concepts & Tools
Lecture 7 Introduction to Shell Programming
Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Python’s Modules Noah Black.
Python Lesson 12 Mr. Kalmes.
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
Lecture 2 Python Basics.
A bit of C programming Lecture 3 Uli Raich.
CSC 352– Unix Programming, Fall 2012
Shell Scripting March 1st, 2004 Class Meeting 7.
Command line arguments
The Linux Operating System
Python Lesson 12 Mr. Kalmes.
Scripting Tools, languages and the Shell intERLab at AIT
What is Bash Shell Scripting?
Introduction to Python
LING 408/508: Computational Techniques for Linguists
Introduction to Python
(Chapter 2) John Carelli, Instructor Kutztown University
Copyright © – Curt Hill Bash Flow of Control Copyright © – Curt Hill.
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Python Modules.
CSC 352– Unix Programming, Fall, 2011
CST8177 Scripting 2: What?.
Introduction to Perl Learning Objectives:
Input and Output Python3 Beginner #3.
EN Software Carpentry Python – A Crash Course Esoteric Sections Compiled Languages.
SPL – PS1 Introduction to C++.
Presentation transcript:

Lab 4: Introduction to Scripting

Source Code Available on Github All the code that is written in this lab is available on my github: https://github.com/petrauskasm/After-Hours- Command-Line-Basics

What is scripting? Scripting is a program that automates the execution of tasks Examples: creating 100 directories connecting to a server Scripting Languages: Python Ruby Perl

Command Line Arguments Most of the scripts that you will write will need some optional input from the user These are called command line arguments Examples: ./fibonacci 50 ./client -p 29773 cbw.sh ./av-detect signatures.av malware_directory

Fibonacci Script in C Goal: create a script in C that will calculate the nth fibonacci number, where n is number you give to the program

Main Function in C We will be focusing on the code in the main function argc is a variable that hold the number of arguments passed to the program argv is a list of the argument Converting the string to an integer Letting the fib function do all the math

Compiling the C program C is a compiled language, so we can't just run the code directly You can compile it two ways gcc -o fibonacci fibonacci.c Makefile A Makefile allows you to run the make command to compile the program instead of typing out gcc … over and over again

Contents of the Makefile The following is the contents of the makefile for the fibonacci program: Typing make fibonacci or make in the terminal will run gcc -o fibonacci fibonacci.c Typing make clean will remove the the compiled program when you are done using it It must be named Makefile

Scripting in Python Scripting in Python or other scripting languages does not require for the code to be compiled You just need the code and a couple other things Shebang statement main function

Shebang Scripting languages require a shebang statement at the beginning of the file This tells the system which language to interpret the rest of the file as Usually in the form #! interpreter Shebang for python

The main function For a python script to run properly, a main function needs to be specified The main function

Command Line Arguments in Python There are a couple of libraries that you can import to parse command line arguments sys argparse Sys is a basic library that will uses a similar method to the C programming language Argparse has more options for interpreting command line arguments

Bash Scripting All of the commands you have been entering on the command line are part of the Bash programming language Examples: echo ls pwd You can write a script to execute these commands

Bash Scripting Example The following is a simple script written in bash Shebang for bash Some random bash commands