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?

Slides:



Advertisements
Similar presentations
Shell Script Assignment 1.
Advertisements

Linux Shell Script. Shell script The first line is used to specify shell program #!/bin/sh Variables variable=“text” variable=0 variable=`program arguments`
More about Shells1-1 More about Shell  Shells (sh, csh, ksh) are m Command interpreters Process the commands you enter m High-level programming languages.
CS 497C – Introduction to UNIX Lecture 32: - Shell Programming Chin-Chih Chang
CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
Linux+ Guide to Linux Certification, Second Edition
Information Networking Security and Assurance Lab National Chung Cheng University 1 What Linux is? Free Unix Like Open Source Network operating system.
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
Introduction to Unix – CS 21 Lecture 13. Lecture Overview Finding files and programs which whereis find xargs Putting it all together for some complex.
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
LINUX COMMAND LINE INTERFACE Lab 3 EECS 448 Dr Fengjun Li and Meenakshi Mishra.
Shell Programming, or Scripting Shirley Moore CPS 5401 Fall August 29,
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.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
An Introduction to Unix Shell Scripting
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.
Lecture 4  C Shell Scripts(Chapter 10). Shell script/program  Shell script: a series of shell commands placed in an ASCII text file  Commands include.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Linux+ Guide to Linux Certification, Third Edition
Shell Scripting AFNOG IX Rabat, Morocco May 2008.
CS465 - UNIX The Bourne Shell.
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.
Workbook 6 – Part 2 The Bash Shell
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
BASH Scripting A beginners guide to Bourne Again SHell scripting.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
Lesson 2 1.Commands 2.Filename Substitution 3.I/O Redirection 4.Command Grouping 5.Shell Responisibilites Review of the Basics.
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.
Writing Scripts Hadi Otrok COEN 346.
Unix Shell Environments February 23rd, 2004 Class Meeting 6.
UNIX shell environments CS 2204 Class meeting 6 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Lab 3 + Using the Terminal 1. "Under Linux there are GUIs (graphical user interfaces). where you can point and click and drag, and hopefully get work.
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
LING 408/508: Programming for Linguists Lecture 8 September 23 rd.
1 © 2000 John Urrutia. All rights reserved. Session 5 The Bourne Shell.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This.
Manually Creating a New User Account Presented by Carl South.
Linux+ Guide to Linux Certification, Second Edition
CS 330 Class 8 Homework A pattern that contains a word with an optional period A pattern that contains Fred with a space (not Freddy) See regexp.txt guest4.htm.
Configuration your environment Many user-configurable Unix programs (such as your shell) read configuration files when they start up. These configuration.
Shell Script Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
Agenda The Bourne Shell – Part I Redirection ( >, >>,
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.
 Prepared by: Eng. Maryam Adel Abdel-Hady
Agenda Customizing a Unix/Linux account Environment Introduction to Start-up Files (.bash_profile,.bashrc,.profile,.kshrc) Safe Methods for Changing Start-up.
Lab 7 Shell Script Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
Shell Features CSCI N321 – System and Network Administration
System Programming and administration CS 308
CAP652 Lecture - Shell Programming
The Linux Operating System
Shell Script Assignment 1.
Lecture 11 bash scripting overview c programming overview moving data between c and bash memory and pointers.
LING 408/508: Computational Techniques for Linguists
John Carelli, Instructor Kutztown University
The Linux Command Line Chapter 24
Linux Shell Script Programming
Lab 7 Shell Script Reference:
CST8177 Scripting 2: What?.
Chapter 3 The UNIX Shells
The Linux Command Line Chapter 24
Presentation transcript:

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? We can do todays lecture in the lab!!!

overview Use the file command (before and after) Add #! to the start of shell script. THIS IS NOT A COMMENT!!! Change the permissions Add it to the path (front/end/twice). (and export it) Which, type commands What if two script paths.

Choosing a shell #! /bin/ksh Specifies the Korn shell #! /bin/bash Is the Bash shell #! bin/perl Forces the shell to execute perl #! /bin/awk –f I think you know this one

Where to put scripts Make a dir /bin or /scripts in your home dir Put a script there (mv command). File hello.sh #will says it’s a text file Add #! /bin/bash as the first line File hello.sh #will say it’s a bash script

File with pdf and ps ~]$ file canonical.pdf canonical.pdf: PDF document, version 1.4 ~]$ file canonical.ps canonical.ps: PostScript document text conforming at level 3.0 ~]$

Change permissions How do we find permissions? What is the error if we try to execute it? chmod 7XX (make it executable) Now check permissions We can now run it without “sh” or “bash” Sh hello.sh Now we can run it directly as hello.sh # JUST LIKE ANY OTHER COMMAND

Change PATH variable echo $PATH /usr/kerberos/bin:/bin:/usr/bin: What is the field separator??? This tells the system where to look for executable files. Add /scripts to end PATH=“$PATH:~/scripts” echo $PATH # to make sure!

Which script $ scripts/hello.sh hello from the scripts dir $ scripts2/hello.sh hello from the SECOND scripts dir $ hello.sh hello from the scripts dir echo $PATH /usr/kerberos/bin:~/scripts

Can still run 2 nd script I can still run the other script but I must refer to it expliclty. ~/scripts2/hello.sh hello from the SECOND scripts dir THE MESSAGE IS ; you should not add your /bin or /script to the start of the PATH variable, because your files will dominate!

Change PATH variable permanently Need to add it to one of your dot login files export PATH (makes available to subshells) ls.*bash* # to list file To run the file Either log out and log back in Or source (filename)

source or. ~]$ source.bash_profile hello John, you have just run.bash_profile ~]$..bash_profile hello John, you have just run.bash_profile ~]$

Stdin stdout Important – if you write to and from standard in and out (i.e. keyboard and screen) Then you can be used in pipelines and redirected more flexibly.