SlideShare a Scribd company logo
1 of 14
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

More Related Content

Similar to lab4.ppt

C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
AashutoshChhedavi
 
Python Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docxPython Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docx
Manohar k
 

Similar to lab4.ppt (20)

C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
 
C intro
C introC intro
C intro
 
Cp week _2.
Cp week _2.Cp week _2.
Cp week _2.
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
 
Software programming and development
Software programming and developmentSoftware programming and development
Software programming and development
 
Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge
 
INTRODUCTION TO C LANGUAGE.pptx
INTRODUCTION TO C LANGUAGE.pptxINTRODUCTION TO C LANGUAGE.pptx
INTRODUCTION TO C LANGUAGE.pptx
 
Computer programming tools and building process
Computer programming tools and building processComputer programming tools and building process
Computer programming tools and building process
 
Chapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfChapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdf
 
Ch07 Programming for Security Professionals
Ch07 Programming for Security ProfessionalsCh07 Programming for Security Professionals
Ch07 Programming for Security Professionals
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Transpilers(Source-to-Source Compilers)
Transpilers(Source-to-Source Compilers)Transpilers(Source-to-Source Compilers)
Transpilers(Source-to-Source Compilers)
 
00 C hello world.pptx
00 C hello world.pptx00 C hello world.pptx
00 C hello world.pptx
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Programming in c
Programming in cProgramming in c
Programming in c
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
 
Python Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docxPython Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docx
 
Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Chapter1.pdf
Chapter1.pdfChapter1.pdf
Chapter1.pdf
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

lab4.ppt

  • 1. Lab 4: Introduction to Scripting
  • 2. 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
  • 3. 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
  • 4. 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
  • 5. 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
  • 6. 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
  • 7. 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
  • 8. 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
  • 9. 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
  • 10. 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
  • 11. The main function  For a python script to run properly, a main function needs to be specified The main function
  • 12. 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
  • 13. 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
  • 14. Bash Scripting Example  The following is a simple script written in bash Shebang for bash Some random bash commands