The Linux Command Line Chapter 24

Slides:



Advertisements
Similar presentations
An Introduction to Programming By :- Vishal Hirani B.Tech II year (CSE)
Advertisements

Linux+ Guide to Linux Certification, Second Edition
CS 497C – Introduction to UNIX Lecture 4: Understanding the UNIX Command Chin-Chih Chang
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 & Shell Scripting Small Group Lecture 4 How to Learn to Code Workshop group/ Erin.
Introduction to Linux and Shell Scripting Jacob Chan.
Using the Bash Shell. Linux Shell Options Linux provides a range of options for shells. bash –The GNU Bourne Again Shell (bash) bsh – The Bourne Shell.
Introduction to Shell Script Programming
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
Chapter Nine Advanced Shell Scripting1 System Programming Advanced Shell Scripting.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
GNU Compiler Collection (GCC) and GNU C compiler (gcc) tools used to compile programs in Linux.
EMT 2390L Lecture 8 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Linux Operations and Administration
This slide deck is for LPI Academy instructors to use for lectures for LPI Academy courses. ©Copyright Network Development Group Module 9 Basic Scripting.
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.
VIM  This is the text editor you will use on the workstation.  You can also edit the text files under windows environment and upload it to the workstation.
Guide to Linux Installation and Administration1 Chapter 4 Running a Linux System.
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.
EMT 2390L Lecture 5 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
Writing Scripts Hadi Otrok COEN 346.
Chapter Six Introduction to Shell Script Programming.
Executable scripts. So far We have made scripts echo hello #for example And called it hello.sh Run it as sh hello.sh This only works from current directory?
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+ Guide to Linux Certification, Second Edition
Lesson 6-Using Utilities to Accomplish Complex Tasks.
1 Week 8 Creating Simple Shell Scripts. 2 Chapter Objectives  In this chapter, you will :  Learn how to create Shell Scripts  Commenting / Making Portable.
Linux Administration Working with the BASH Shell.
BASH Scripting #SWIFT sareebro. What is a shell script? Script: a writing; a written document – Webster's Dictionary A shell script is an easy-to-use.
 Prepared by: Eng. Maryam Adel Abdel-Hady
Lab 7 Shell Script Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
CIRC Winter Boot Camp 2017 Baowei Liu
SUSE Linux Enterprise Desktop Administration
CS306 Lab Workout 2 Fall 2017.
Prepared by: Eng. Maryam Adel Abdel-Hady
Bash Introduction (adapted from chapters 1 and 2 of bash Cookbook by Albing, Vossing, & Newham) CPTE 440 John Beckett.
Chapter 9 Shell Programming
By Jonathan Rinfret CREATING A BASH SCRIPT By Jonathan Rinfret
Bash 101 Intro to Shell Scripting; Lightning
Linux.
The Linux Command Line Chapter 14
The Linux Command Line Chapter 16
Tutorial of shell script
The Linux Command Line Chapter 12
The Linux Command Line Chapter 2
The Linux Command Line Chapter 10
The Linux Command Line Chapter 7
The Linux Command Line Chapter 24
The Linux Command Line Chapter 11
The Linux Command Line Chapter 3
The Linux Command Line Chapter 26
The Linux Command Line Chapter 28
The Linux Command Line Chapter 9
Run Java file with Window cmd
The Linux Command Line Chapter 17
The Linux Command Line Chapter 4
The Linux Command Line Chapter 25
Week 1 – Lesson 2: Creating Shell Scripts, Linux Commands
The Linux Command Line Chapter 14
Lab 7 Shell Script Reference:
The Linux Command Line Chapter 5
The Linux Command Line Chapter 3
The Linux Command Line Chapter 4
The Linux Command Line Chapter 12
The Linux Command Line Chapter 11
The Linux Command Line Chapter 26
Presentation transcript:

The Linux Command Line Chapter 24 Writing Your First Script Prepared by Dr. Reyes, New York City College of Technology

Shell Scripts What is a script? How to write a shell script? A text file containing a set of commands The file is read by the shell and the commands are executed as if they were typed How to write a shell script? Write a script file using a text editor (e.g. vi/vim, gedit) Make the script executable (assign appropriate permission) Specify the location of the script so that the shell can find it

The echo command echo – A command that displays a line of text into the console.

Hello World Script Our first script Script Features: #! (shebang) - is a sequence of characters that indicates the name of the interpreter to be used to execute the script. Used in the first line of a script. # - is a symbol used to specify comments echo – command used to display a line of text

Create the Hello World Script Execute the following command to create a file named hello_world: vi hello_world Type this code in the hello_world file: #!/bin/bash # This is our first script. echo 'Hello World!‘ Close and save the file with the command: :wq

Execute the Hello World Script First need to make the file executable. For that execute the following command We will discuss file permissions in detail later in the course After chmod, execute the script as follows

Scripts Location Scripts are usually located in the following directories ~/bin - for personal use /usr/local/bin – for anyone to use /usr/local/sbin – for administrators to use Custom directories added to the PATH variable Best Practices Use correct indentation techniques for multiple commands For commands that span several lines, use the line-continuation sequences (backslash)