Linux Shell Scripting Tutorial V2.0

Total Page:16

File Type:pdf, Size:1020Kb

Linux Shell Scripting Tutorial V2.0 Linux Shell Scripting Tutorial v2.0 Written by Vivek Gite <[email protected]> and Edited By Various Contributors PDF generated using the open source mwlib toolkit. See http://code.pediapress.com/ for more information. PDF generated at: Mon, 31 May 2010 07:27:26 CET Contents Articles Linux Shell Scripting Tutorial - A Beginner's handbook:About 1 Chapter 1: Quick Introduction to Linux 4 What Is Linux 4 Who created Linux 5 Where can I download Linux 6 How do I Install Linux 6 Linux usage in everyday life 7 What is Linux Kernel 7 What is Linux Shell 8 Unix philosophy 11 But how do you use the shell 12 What is a Shell Script or shell scripting 13 Why shell scripting 14 Chapter 1 Challenges 16 Chapter 2: Getting Started With Shell Programming 17 The bash shell 17 Shell commands 19 The role of shells in the Linux environment 21 Other standard shells 23 Hello, World! Tutorial 25 Shebang 27 Shell Comments 29 Setting up permissions on a script 30 Execute a script 31 Debug a script 32 Chapter 2 Challenges 33 Chapter 3:The Shell Variables and Environment 34 Variables in shell 34 Assign values to shell variables 38 Default shell variables value 40 Rules for Naming variable name 41 Display the value of shell variables 42 Quoting 46 The export statement 49 Unset shell and environment variables 50 Getting User Input Via Keyboard 50 Perform arithmetic operations 54 Create an integer variable 56 Create the constants variable 57 Bash variable existence check 58 Customize the bash shell environments 59 Recalling command history 63 Path name expansion 65 Create and use aliases 67 The tilde expansion 69 Startup scripts 70 Using aliases 72 Changing bash prompt 73 Setting shell options 77 Setting system wide shell options 82 Chapter 3 Challenges 83 Chapter 4: Conditionals Execution (Decision Making) 84 Bash structured language constructs 84 Test command 86 If structures to execute code based on a condition 87 If. .else. .fi 89 Nested ifs 92 Multilevel if- then- else 93 The exit status of a command 94 Conditional execution 97 Logical AND && 97 Logical OR || 98 Logical Not ! 99 Conditional expression using [ 101 Conditional expression using <nowiki>[[</ nowiki> 102 Numeric comparison 102 String comparison 104 File attributes comparisons 105 Shell command line parameters 110 How to use positional parameters 112 Parameters Set by the Shell 114 Create usage messages 115 Exit command 117 The case statement 119 Dealing with case sensitive pattern 123 Chapter 4 Challenges 126 Chapter 5: Bash Loops 127 The for loop statement 127 Nested for loop statement 133 The while loop statement 135 Use of : to set infinite while loop 139 The until loop statement 141 The select loop statement 143 Exit the select loop statement 146 Using the break statement 148 Using the continue statement 150 Command substitution 153 Chapter 5 Challenges 155 Chapter 6: Shell Redirection 157 Input and Output 157 Standard input 158 Standard output 159 Standard error 160 Empty file creation 161 / dev/ null discards unwanted output 162 Here documents 164 Here strings 166 Redirection of standard error 167 Redirection of standard output 169 Appending redirected output 170 Redirection of both standard error and output 170 Writing output to files 171 Assigns the file descriptor (fd) to file for output 173 Assigns the file descriptor (fd) to file for input 174 Closes the file descriptor (fd) 175 Opening the file descriptors for reading and writing 175 Reads from the file descriptor (fd) 176 Executes commands and send output to the file descriptor (fd) 179 Chapter 6 Challenges 185 Chapter 7: Pipes and Filters 186 Linking Commands 186 Multiple commands 187 Putting jobs in background 188 Pipes 190 How to use pipes to connect programs 191 Input redirection in pipes 193 Output redirection in pipes 194 Why use pipes 194 Filters 195 Chapter 7 Challenges 197 Chapter 8: Traps 198 Signals 198 What is a Process? 199 How to view Processes 201 Sending signal to Processes 204 Terminating Processes 206 Shell signal values 209 The trap statement 210 How to clear trap 212 Include trap statements in a script 214 Use the trap statement to catch signals and handle errors 216 What is a Subshell? 220 Compound command 222 Exec command 223 Chapter 8 Challenges 224 Chapter 9: Functions 225 Writing your first shell function 225 Displaying functions 226 Removing functions 228 Defining functions 228 Writing functions 231 Calling functions 232 Pass arguments into a function 237 Local variable 240 Returning from a function 243 Shell functions library 245 Source command 248 Recursive function 249 Putting functions in background 251 Chapter 9 Challenges 253 Chapter 10: Interactive Scripts 254 Menu driven scripts 254 Getting information about your system 256 Bash display dialog boxes 260 Dialog customization with configuration file 263 A yes/ no dialog box 267 An input dialog box 268 A password box 270 A menu box 273 A progress bar (gauge box) 276 The form dialog for input 279 Console management 281 Get the name of the current terminal 282 Fixing the display with reset 283 Get screen width and hight with tput 284 Moving the cursor with tput 284 Display centered text in the screen in reverse video 285 Set the keyboard leds 286 Turn on or off NumLock leds 286 Turn on or off CapsLock leds 287 Turn on or off ScrollLock leds 287 /etc 288 Shell scripting help 288 Recommended Books 288 References Article Sources and Contributors 289 Image Sources, Licenses and Contributors 293 Article Licenses License 294 Linux Shell Scripting Tutorial - A Beginner's handbook:About 1 Linux Shell Scripting Tutorial - A Beginner's handbook:About This document is Copyright (C) 1999-2009 by Vivek Gite [1] and its contributors. Some rights reserved. Audience This book is for students and Linux System Administrators. It provides the skills to read, write, and debug Linux shell scripts using bash shell. The book begins by describing Linux and simple scripts to automate frequently executed commands and continues by describing conditional logic, user interaction, loops, menus, traps, and functions. Finally, book covers various sys admin related scripts such as making a backup, using cron jobs, writing interactive tools, web based tools, remote login, ftp and database backup related scripts. This book is intended for Linux system administrators or students who have mastered the basics of a Linux Operating System. You should be able to: • Login to local or remote Linux system. • Use basic Linux commands, such as cp, mv, rm, man,less, chmod and others. • Create and edit text files in vi or any other text editor. • GUI is not required except for interactive GTK+ based GUI scripts. Licensing Information This book is available under Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported [2]. • You are free: • to Share — to copy, distribute and transmit the work • to Remix — to adapt the work • Under the following conditions: • Attribution — If you republish this content, we require that you: 1. Indicate that the content is from "Linux Shell Scripting Tutorial - A Beginner's handbook" (http:/ / bash. cyberciti. biz/ guide/ Main_Page), and nixCraft (http:/ / nixcraft. com/ ). 2. Hyperlink to the original article on the source site (e.g., http:/ / bash. cyberciti. biz/ guide/ What_Is_Linux) 3. Show the author name (e.g., Vivek Gite) for all pages. 4. Hyperlink each contributors name back to their profile page on the source wiki (e.g., http:/ / bash. cyberciti. biz/ guide/ User:USERNAME) • Noncommercial — You may not use this work for commercial purposes including the Internet ad supported websites or any sort of print media. • Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one. With the understanding that: • Waiver — Any of the above conditions can be waived if you get permission from the copyright holder (i.e. the Author: Vivek Gite). • Other Rights — In no way are any of the following rights affected by the license: • Your fair dealing or fair use rights; • The author's moral rights; • Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights. Linux Shell Scripting Tutorial - A Beginner's handbook:About 2 • Notice — For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page (http:/ / bash. cyberciti. biz/ guide/ Linux_Shell_Scripting_Tutorial_-_A_Beginner%27s_handbook:About). History • Ver.0.8 - 1998 - First draft with only 8 pages. • Ver.0.9 - 2000 - Second draft with a few more pages. • Ver.1.0 - 2002 - Third draft published on freeos.com. • Ver.1.5r3 - 2004 - Updated version published on freeos.com. • Ver.2.0.beta - Aug-2009 - Wiki started. • This document is now in a wiki format. • All user contributed content licensed under Attribution-Noncommercial-Share Alike 3.0 Unported. Disclaimer • This web site / wiki ("Site") provides educational learning information on Linux scripting for sys admin work, but you are 100% responsible for what you do or don't do with it. • The information compiled by Vivek Gite (and its contributors) as well as the links to complimentary material are provided "as is" with no warranty, express or implied, for their accuracy or reliability. • You use these sites at your own risk, and acknowledge that, while every effort has been made to correct errors before they appear, this site may include certain inaccuracies, errors, or omissions. nixCraft makes no representations as to the suitability, reliability, availability, timeliness, and accuracy of the information on this site for any purpose.
Recommended publications
  • Unix Introduction
    Unix introduction Mikhail Dozmorov Summer 2018 Mikhail Dozmorov Unix introduction Summer 2018 1 / 37 What is Unix Unix is a family of operating systems and environments that exploits the power of linguistic abstractions to perform tasks Unix is not an acronym; it is a pun on “Multics”. Multics was a large multi-user operating system that was being developed at Bell Labs shortly before Unix was created in the early ’70s. Brian Kernighan is credited with the name. All computational genomics is done in Unix http://www.read.seas.harvard.edu/~kohler/class/aosref/ritchie84evolution.pdfMikhail Dozmorov Unix introduction Summer 2018 2 / 37 History of Unix Initial file system, command interpreter (shell), and process management started by Ken Thompson File system and further development from Dennis Ritchie, as well as Doug McIlroy and Joe Ossanna Vast array of simple, dependable tools that each do one simple task Ken Thompson (sitting) and Dennis Ritchie working together at a PDP-11 Mikhail Dozmorov Unix introduction Summer 2018 3 / 37 Philosophy of Unix Vast array of simple, dependable tools Each do one simple task, and do it really well By combining these tools, one can conduct rather sophisticated analyses The Linux help philosophy: “RTFM” (Read the Fine Manual) Mikhail Dozmorov Unix introduction Summer 2018 4 / 37 Know your Unix Unix users spend a lot of time at the command line In Unix, a word is worth a thousand mouse clicks Mikhail Dozmorov Unix introduction Summer 2018 5 / 37 Unix systems Three common types of laptop/desktop operating systems: Windows, Mac, Linux. Mac and Linux are both Unix-like! What that means for us: Unix-like operating systems are equipped with “shells”" that provide a command line user interface.
    [Show full text]
  • Shell Scripting with Bash
    Introduction to Shell Scripting with Bash Charles Jahnke Research Computing Services Information Services & Technology Topics for Today ● Introductions ● Basic Terminology ● How to get help ● Command-line vs. Scripting ● Variables ● Handling Arguments ● Standard I/O, Pipes, and Redirection ● Control Structures (loops and If statements) ● SCC Job Submission Example Research Computing Services Research Computing Services (RCS) A group within Information Services & Technology at Boston University provides computing, storage, and visualization resources and services to support research that has specialized or highly intensive computation, storage, bandwidth, or graphics requirements. Three Primary Services: ● Research Computation ● Research Visualization ● Research Consulting and Training Breadth of Research on the Shared Computing Cluster (SCC) Me ● Research Facilitator and Administrator ● Background in biomedical engineering, bioinformatics, and IT systems ● Offices on both CRC and BUMC ○ Most of our staff on the Charles River Campus, some dedicated to BUMC ● Contact: [email protected] You ● Who has experience programming? ● Using Linux? ● Using the Shared Computing Cluster (SCC)? Basic Terminology The Command-line The line on which commands are typed and passed to the shell. Username Hostname Current Directory [username@scc1 ~]$ Prompt Command Line (input) The Shell ● The interface between the user and the operating system ● Program that interprets and executes input ● Provides: ○ Built-in commands ○ Programming control structures ○ Environment
    [Show full text]
  • UKUI: a Lightweight Desktop Environment Based on Pluggable
    2016 International Conference on Artificial Intelligence and Computer Science (AICS 2016) ISBN: 978-1-60595-411-0 UKUI: A Lightweight Desktop Environment Based on Pluggable Framework for Linux Distribution Jie YU1, Lu SI1,*, Jun MA1, Lei LUO1, Xiao-dong LIU1, Ya-ting KUANG2, Huan PENG2, Rui LI1, Jin-zhu KONG2 and Qing-bo WU1 1College of Computer, National University of Defense Technology, Changsha, China 2Tianjin KYLIN Information Technology Co., Ltd, Tianjin, China *[email protected] *Corresponding author Keywords: Desktop environment, Ubuntu, User interface. Abstract. Ubuntu is an operating system with Linux kernel based on Debian and distributed as free and open-source software. It uses Unity as its default desktop environment, which results in more difficulties of usage for Microsoft Windows users. In this paper, we present a lightweight desktop environment named UKUI based on UbuntuKylin, the official Chinese version of Ubuntu, for Linux distribution. It is designed as a pluggable framework and provides better user experience during human-computer interaction. In order to evaluate the performance of UKUI, a set of testing bench suits were performed on a personal computer. Overall, the results showed that UKUI has better performance compared with Unity. Introduction Linux is a freely available operating system (OS) originated by Linux Torvalds and further developed by thousands of others. Typically, Linux is packaged in a form known as a Linux distribution for both desktop and server use. Some of the most popular mainstream Linux distributions are Red Hat [1], Ubuntu [2], Arch [3], openSUSY [4], Gentoo [5], etc. There are several desktop environments available for nowadays modern Linux distributions, such as XFCE [6], GNOME [7], KDE [8] and LXDE [9].
    [Show full text]
  • Beginning Portable Shell Scripting from Novice to Professional
    Beginning Portable Shell Scripting From Novice to Professional Peter Seebach 10436fmfinal 1 10/23/08 10:40:24 PM Beginning Portable Shell Scripting: From Novice to Professional Copyright © 2008 by Peter Seebach All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-1043-6 ISBN-10 (pbk): 1-4302-1043-5 ISBN-13 (electronic): 978-1-4302-1044-3 ISBN-10 (electronic): 1-4302-1044-3 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Frank Pohlmann Technical Reviewer: Gary V. Vaughan Editorial Board: Clay Andres, Steve Anglin, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Michelle Lowman, Matthew Moodie, Jeffrey Pepper, Frank Pohlmann, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Project Manager: Richard Dal Porto Copy Editor: Kim Benbow Associate Production Director: Kari Brooks-Copony Production Editor: Katie Stence Compositor: Linda Weidemann, Wolf Creek Press Proofreader: Dan Shaw Indexer: Broccoli Information Management Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013.
    [Show full text]
  • GNU Readline Library
    GNU Readline Library Edition 2.1, for Readline Library Version 2.1. March 1996 Brian Fox, Free Software Foundation Chet Ramey, Case Western Reserve University This do cument describ es the GNU Readline Library, a utility which aids in the consistency of user interface across discrete programs that need to provide a command line interface. Published by the Free Software Foundation 675 Massachusetts Avenue, Cambridge, MA 02139 USA Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this p ermission notice are preserved on all copies. Permission is granted to copy and distribute mo di ed versions of this manual under the con- ditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a p ermission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another lan- guage, under the ab ove conditions for mo di ed versions, except that this p ermission notice may b e stated in a translation approved by the Foundation. c Copyright 1989, 1991 Free Software Foundation, Inc. Chapter 1: Command Line Editing 1 1 Command Line Editing This chapter describ es the basic features of the GNU command line editing interface. 1.1 Intro duction to Line Editing The following paragraphs describ e the notation used to representkeystrokes. i h i h C-k is read as `Control-K' and describ es the character pro duced when the k The text key is pressed while the Control key is depressed. h i The text M-k is read as `Meta-K' and describ es the character pro duced when the meta h i key if you have one is depressed, and the k key is pressed.
    [Show full text]
  • Version 7.8-Systemd
    Linux From Scratch Version 7.8-systemd Created by Gerard Beekmans Edited by Douglas R. Reno Linux From Scratch: Version 7.8-systemd by Created by Gerard Beekmans and Edited by Douglas R. Reno Copyright © 1999-2015 Gerard Beekmans Copyright © 1999-2015, Gerard Beekmans All rights reserved. This book is licensed under a Creative Commons License. Computer instructions may be extracted from the book under the MIT License. Linux® is a registered trademark of Linus Torvalds. Linux From Scratch - Version 7.8-systemd Table of Contents Preface .......................................................................................................................................................................... vii i. Foreword ............................................................................................................................................................. vii ii. Audience ............................................................................................................................................................ vii iii. LFS Target Architectures ................................................................................................................................ viii iv. LFS and Standards ............................................................................................................................................ ix v. Rationale for Packages in the Book .................................................................................................................... x vi. Prerequisites
    [Show full text]
  • Introduction to Unix
    Introduction to Unix Rob Funk <[email protected]> University Technology Services Workstation Support http://wks.uts.ohio-state.edu/ University Technology Services Course Objectives • basic background in Unix structure • knowledge of getting started • directory navigation and control • file maintenance and display commands • shells • Unix features • text processing University Technology Services Course Objectives Useful commands • working with files • system resources • printing • vi editor University Technology Services In the Introduction to UNIX document 3 • shell programming • Unix command summary tables • short Unix bibliography (also see web site) We will not, however, be covering these topics in the lecture. Numbers on slides indicate page number in book. University Technology Services History of Unix 7–8 1960s multics project (MIT, GE, AT&T) 1970s AT&T Bell Labs 1970s/80s UC Berkeley 1980s DOS imitated many Unix ideas Commercial Unix fragmentation GNU Project 1990s Linux now Unix is widespread and available from many sources, both free and commercial University Technology Services Unix Systems 7–8 SunOS/Solaris Sun Microsystems Digital Unix (Tru64) Digital/Compaq HP-UX Hewlett Packard Irix SGI UNICOS Cray NetBSD, FreeBSD UC Berkeley / the Net Linux Linus Torvalds / the Net University Technology Services Unix Philosophy • Multiuser / Multitasking • Toolbox approach • Flexibility / Freedom • Conciseness • Everything is a file • File system has places, processes have life • Designed by programmers for programmers University Technology Services
    [Show full text]
  • C Shell Scripts File Permissions a Simple Spelling Checker Command
    Cshell scripts Asimple spelling checker mylatex1.csh #!/bin/csh #!/bin/csh tr -cs "[:alpha:]" "[\n*]" < $1 \ latex file.tex |tr"[:upper:]" "[:lower:]" \ dvips -f file.dvi > file.ps |sort -u > tempfile rm file.aux file.dvi file.log comm -23 tempfile /usr/share/dict/words rm tempfile mylatex2.csh #!/bin/csh Put one word per line \ |convert everything to lowercase \ latex $1.tex |sor t the words,remove duplicates and write the result to ’tempfile’. dvips -f $1.dvi > $1.ps rm $1.aux $1.dvi $1.log Pr int those words in ’tempfile’ that are not in the dictionary. Remove the temporar y file. Graham Kemp,Chalmers University of Technology Graham Kemp,Chalmers University of Technology File permissions Command substitution in a script ls -l To include the output from one command within the command line for another command, enclose the command whose output is to be included rwxrwx rwx within ‘backquotes‘. For example: rwxr -xr -x #!/bin/csh 111101101 echo Date and time is: date echo 1111 011 012 = 7558 echo "Your username is:" ‘whoami‘ echo "Your current directory is:" ‘pwd‘ chmod 755 file.sh chmod u+x file.sh chmod -R a+rX . Graham Kemp,Chalmers University of Technology Graham Kemp,Chalmers University of Technology Editing several files at once (1) sed scripts Suppose wewant to change ‘‘cie’’to‘‘cei’’inall files in the current grep href publications.html \ director y whose name ends with ‘‘.tex’’. |sed ’s/[ˆ"]*"//’ \ |sed ’s/".*//’ #!/bin/csh Instead of giving a single editing command on the command line,wecan ls *.tex | sed ’s/.*/sed s\/cie\/cei\/g & > &tmp/’ > s1 create a script file containing a sequence of editing commands.
    [Show full text]
  • Shell Script & Advance Features of Shell Programming
    Kirti Kaushik et al, International Journal of Computer Science and Mobile Computing, Vol.4 Issue.4, April- 2015, pg. 458-462 Available Online at www.ijcsmc.com International Journal of Computer Science and Mobile Computing A Monthly Journal of Computer Science and Information Technology ISSN 2320–088X IJCSMC, Vol. 4, Issue. 4, April 2015, pg.458 – 462 RESEARCH ARTICLE Shell Script & Advance Features of Shell Programming Kirti Kaushik* Roll No.15903, CS, Department of Computer science, Dronacharya College of Engineering, Gurgaon-123506, India Email: [email protected] Jyoti Yadav Roll No. 15040, CS, Department of Applied Computer science, Dronacharya College of Engineering, Gurgaon-123506, India Email: [email protected] Kriti Bhatia Roll No. 15048, CS, Department of Applied Computer science, Dronacharya College of Engineering, Gurgaon-123506, India Email: [email protected] Abstract-- In this research paper, the idea of shell scripting and writing computer programs is examined and different parts of shell programming are likewise contemplated. A shell script is a PC system intended to be controlled by the UNIX shell which is a charge line translator. The different tongues of shell scripts are thought to be scripting dialects. Regular operations performed by shell scripts incorporate document control, program execution, and printing content. A shell script can give an advantageous variety ofa framework order where unique environment settings, charge alternatives, or post-transforming apply naturally, yet in a manner that permits the new script to still go about as a completely typical UNIX summon. The real ideas like Programming in the Borne and C-shell, in which it would be clarified that how shell programming could be possible in Borne and C-shell.
    [Show full text]
  • SOAP / REST and IBM I
    1/11/18 SOPA / REST and IBM i Tim Rowe- [email protected] Business Architect Application Development © 2017 International Business Machines Corporation Using a REST API with Watson https://ibm-i-watson-test.mybluemix.net/ 2 © 2017 International Business Machines Corporation 1 1/11/18 ™ What is an API - Agenda •What is an API •What is a Web Service •SOAP vs REST – What is SOAP – What is REST – Benefits – Drawbacks 3 © 2017 International Business Machines Corporation ™ Connections Devices There Here Applications 4 © 2017 International Business Machines Corporation 2 1/11/18 ™ 5 © 2017 International Business Machines Corporation ™ 6 © 2017 International Business Machines Corporation 3 1/11/18 ™ 7 © 2017 International Business Machines Corporation ™ 8 © 2017 International Business Machines Corporation 4 1/11/18 ™ API Definition Application Programming Interface 9 © 2017 International Business Machines Corporation ™ API Definition 10 © 2017 International Business Machines Corporation 5 1/11/18 ™ APIs - Simple Simple way to connect endpoints. Send a request and receive a response. 11 © 2017 International Business Machines Corporation ™ Example Kitchen 12 © 2017 International Business Machines Corporation 6 1/11/18 ™ 13 © 2017 International Business Machines Corporation ™ Not just a buzz-word, but rather the evolution of services- oriented IT. Allows users, businesses & partners the ability to interact in new and different ways resulting in the growth (in some cases the revolution) of business. 14 © 2017 International Business Machines Corporation
    [Show full text]
  • A First Course to Openfoam
    Basic Shell Scripting Slides from Wei Feinstein HPC User Services LSU HPC & LON [email protected] September 2018 Outline • Introduction to Linux Shell • Shell Scripting Basics • Variables/Special Characters • Arithmetic Operations • Arrays • Beyond Basic Shell Scripting – Flow Control – Functions • Advanced Text Processing Commands (grep, sed, awk) Basic Shell Scripting 2 Linux System Architecture Basic Shell Scripting 3 Linux Shell What is a Shell ▪ An application running on top of the kernel and provides a command line interface to the system ▪ Process user’s commands, gather input from user and execute programs ▪ Types of shell with varied features o sh o csh o ksh o bash o tcsh Basic Shell Scripting 4 Shell Comparison Software sh csh ksh bash tcsh Programming language y y y y y Shell variables y y y y y Command alias n y y y y Command history n y y y y Filename autocompletion n y* y* y y Command line editing n n y* y y Job control n y y y y *: not by default http://www.cis.rit.edu/class/simg211/unixintro/Shell.html Basic Shell Scripting 5 What can you do with a shell? ▪ Check the current shell ▪ echo $SHELL ▪ List available shells on the system ▪ cat /etc/shells ▪ Change to another shell ▪ csh ▪ Date ▪ date ▪ wget: get online files ▪ wget https://ftp.gnu.org/gnu/gcc/gcc-7.1.0/gcc-7.1.0.tar.gz ▪ Compile and run applications ▪ gcc hello.c –o hello ▪ ./hello ▪ What we need to learn today? o Automation of an entire script of commands! o Use the shell script to run jobs – Write job scripts Basic Shell Scripting 6 Shell Scripting ▪ Script: a program written for a software environment to automate execution of tasks ▪ A series of shell commands put together in a file ▪ When the script is executed, those commands will be executed one line at a time automatically ▪ Shell script is interpreted, not compiled.
    [Show full text]
  • A Multiplatform Pseudo Terminal
    A Multi-Platform Pseudo Terminal API Project Report Submitted in Partial Fulfillment for the Masters' Degree in Computer Science By Qutaiba Mahmoud Supervised By Dr. Clinton Jeffery ABSTRACT This project is the construction of a pseudo-terminal API, which will provide a pseudo-terminal interface access to interactive programs. The API is aimed at developing an extension to the Unicon language to allow Unicon programs to easily utilize applications that require user interaction via a terminal. A pseudo-terminal is a pair of virtual devices that provide a bidirectional communication channel. This project was constructed to enable an enhancement to a collaborative virtual environment, because it will allow external tools such to be utilized within the same environment. In general the purpose of this API is to allow the UNICON runtime system to act as the user via the terminal which is provided by the API, the terminal is in turn connected to a client process such as a compiler, debugger, or an editor. It can also be viewed as a way for the UNICON environment to control and customize the input and output of external programs. Table of Contents: 1. Introduction 1.1 Pseudo Terminals 1.2 Other Terminals 1.3 Relation To Other Pseudo Terminal Applications. 2. Methodology 2.1 Pseudo Terminal API Function Description 3. Results 3.1 UNIX Implementation 3.2 Windows Implementation 4. Conclusion 5. Recommendations 6. References Acknowledgments I would like to thank my advisor, Dr. Clinton Jeffery, for his support, patience and understanding. Dr. Jeffery has always been prompt in delivering and sharing his knowledge and in providing his assistance.
    [Show full text]