Shell Programming

Total Page:16

File Type:pdf, Size:1020Kb

Shell Programming Shell Programming Erwin Earley ([email protected]) Sr. Professional Services Consultant @erwinephp @RougeWaveInc @Zend © 2018 Rogue Wave Software, Inc. All Rights Reserved. 1 Agenda • What is a Shell? • Working with the shell • Programming Constructs © 2018 Rogue Wave Software, Inc. All Rights Reserved. 2 What is a Shell? • The command line used on “Unix™” systems (as well as Unix-like systems) • Like CL it can be used interactively, or run as a Program • Like CL most commands are actually Programs that get called – There are some “built in” commands • Unlike CL there are a number of varieties of shell – sh bourne shell – csh c shell – ksh korn shell – bash bourne again shell – qsh Q shell • There are some similarities and some differences • Most of the discussion here is not oPerating system sPecific – Will worK on AIX, Linux, QSH in OS/400, other nasty Unix variants, etc © 2018 Rogue Wave Software, Inc. All Rights Reserved. 3 Why do we care about the shell? • All system configuration operations can be done through the shell – often more quickly then through a GUI • It may be the only environment available in the case of a system crash • Shell scripts can automate most routine tasks such as backups, scheduled emails, etc. • GUI can be used for a great amount of admin activities – However, the shell tends to be a comfort zone providing ability to fix things in case something goes wrong © 2018 Rogue Wave Software, Inc. All Rights Reserved. 4 Different Types of Shells • A number of shells are available each providing function/usability customized to a particular type of user: • Popular shells include: – BASH (Bourne Again Shell) – PDKsh (Public Domain Korn Shell) – csh (C shell) – mc (Midnight Commander) – QSHELL (PASE shell) – ksh (Korn shell, default on AIX) • Difference tends to be in scripting capabilities and user interface – Items such as command recall and file name completion are typically different © 2018 Rogue Wave Software, Inc. All Rights Reserved. 5 Login Shell vs. Non-Login Shell • Login Shell: Shell executed when user logs in to the system. – Typically performs general setup – initializes the terminal, sets some variables, etc. • Non-login shell: Either subshells (started from the login shell), shells started by the GUI desktop, or disconnected shells started by a command – Remember that shell is simply another command on the system • Login shells unlike Non-login shells read a series of configuration files: Login Shell: Non Login Shell: On login On startup if "/etc/profile”" source it if "~/.bashrc" exists, source it if "~/.bash_profile" exists, source it else if "~/.bash_login" exists, source it if "~/.profile" exists, source it On exit if "~/.bash_logout" exists, source it © 2018 Rogue Wave Software, Inc. All Rights Reserved. 6 Starting with bash • bash stands for Bourne Again Shell Available in PASE, more – Developed by Brian Fox in 1987 on that coming up! – One of the most popular shells available in Linux • Bash incorporates features of the Korn and C shell (ksh and csh) • Bash configuration files: /bin/bash – Bash executable /etc/profile – System wide initialization file for login shells ~/.bash_profile – Personal initialization file for login shells ~/.bashrc – Personal per-interactive-shell startup file ~/.bash_logout – Login shell clean file that executes when shell exits © 2018 Rogue Wave Software, Inc. All Rights Reserved. 7 A little more on BASH • Default Linux shell – This can be changed in a variety of ways • /etc/profile – login shell • $HOME/.profile • Magic string within the script (more on this in a moment) • Very powerful as a command line shell – Recall previous commands – Command and file completion with the <TAB> key • Many programming features – Loops and conditionals © 2018 Rogue Wave Software, Inc. All Rights Reserved. 8 Shell Environment • The shell is an environment where commands can be entered and the Operations system can respond to them • A key concept to the environment is environment variables – There are a large number of environment variables – HISTFILE: points to file containing the shell history, defaults to ~/.bash_history – HISTFILESIZE: how man last commands you wish to have in history – HOME: points to your home directory – PATH: set of directories to search when trying to execute a command – PS1: Prompt variable NOTE: All of these environment variables – USER: username are available when running bash in the PASE environment. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 9 Shell metacharacters Symbol Meaning > Output redirection >> Output redirection (append) < Input redirection * File substitution wildcard; zero or more characters ? File substitution wildcard; one character [ ] File substitution wildcard; any character between brackets `cmd` Command substitution $(cmd) Command substitution | The pipe (connect output of command on right to input on command on left) ; Command Sequence || OR conditional execution && AND conditional execution © 2018 Rogue Wave Software, Inc. All Rights Reserved. 10 Shell metacharacters (continued) Symbol Meaning ( ) Group commands & Run command in the background # Comment $ Expand the value of a variable \ Prevent or escape interpretation of the next character << Input redirection " $val " Literal with variable substitution ' $val ' Literal without variable substitution © 2018 Rogue Wave Software, Inc. All Rights Reserved. 11 Useful Shell Constructs • Arrow Up & Down: Scroll through recent commands used • &&: command is only executed if preceding command was successful: command1 && command2 • alias: sets a command alias or prints defined aliases alias wrklnk=ls • bg[jobid]: Resumes the suspended job in the background • cd: changes current directory to directory indicated cd /home © 2018 Rogue Wave Software, Inc. All Rights Reserved. 12 Useful Shell Constructs (continued) • echo: Outputs the arguments echo “hello world” • find [path][expression]: searches the directory indicating looking for files that match expression: find / -name passwd –print • pwd – Prints the absolute pathname of the current working directory • unalias – Removes an alias • history – displays command history with line numbers • umask – User file creation mask • logout: exits the shell environment • exit [n]: exits shell environment with exit status n © 2018 Rogue Wave Software, Inc. All Rights Reserved. 13 More information on Bash • Just enter the command – $ man Bash • Manual page for Bash is aBout 5,000 lines!! NOTE: the manual pages are not yet availaBle in the PASE environment. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 14 "bash"ing PASE – yes I went there ;-) • The bash shell is available for PASE – It is part of the RPM pile • Step 1: Install the RPM pile bootstrap • Step 2: Install bash yum install bash • Step 3: Create a home directory: PATH=/QOpenSys/pkgs/bin:$PATH mkdir /home/<username> export PATH • Step 4: Create a .profile • Step 5: Install nano bash yum install nano © 2018 Rogue Wave Software, Inc. All Rights Reserved. 15 qsh • A version of a shell for System i • Has many of the same features as bash • RTFM This is an excellent and comprehensive book! © 2018 Rogue Wave Software, Inc. All Rights Reserved. 16 Programming Constructs © 2018 Rogue Wave Software, Inc. All Rights Reserved. 17 The First Shell Program #!/bin/bash NOTE: on IBM i the path to bash is echo Hello World /QOpenSys/pkgs/bin/bash However, symbolic links have been created to /bin/bash and /usr/bin/bash This means that many existing scripts can be brought over from Linux environments and run unchanged in PASE under the bash shell • This is called a shell script • The first line "#!/bin/bash" is a magic string • When a file is loaded if the first two characters are “#!” (called shebang) then the remainder of the line is used as the program to run the file • "#!/home/erwin/my_nice_program" is a valid shell script • echo is a built-in command that Just displays the rest of the line © 2018 Rogue Wave Software, Inc. All Rights Reserved. 18 Creating a shell program • Use a text editor –Traditional Unix editors include vi and emacs –More user friendly editors include “nano” • On IBM i –Install and use nano from a PASE session © 2018 Rogue Wave Software, Inc. All Rights Reserved. 19 Writing Your Shell Script Using nano © 2018 Rogue Wave Software, Inc. All Rights Reserved. 20 Running Your Shell Script earley@testbed:~$ ls –l test.sh -rw-r—r– 1 earley earley 32 2006-09-11 08:54 test.sh earley@testbed:~$ test.sh -bash: test.sh: command not found earley@testbed:~$ • We have a "test.sh" program in our directory • Lets try and run it • Doesn’t work! Why not!?!? © 2018 Rogue Wave Software, Inc. All Rights Reserved. 21 Running Your Shell Script earley@testbed:~$ echo $PATH /home/earley/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/ usr/bin:/sbin:/bin:/usr/bin/X11 earley@testbed:~$ . test.sh Hello World earley@testbed:~$ • The program is not in the “path” – The current directory is not in the path • Can run a shell script by typing “.” – Means load the file into the current shell © 2018 Rogue Wave Software, Inc. All Rights Reserved. 22 Running Your Shell Script earley@testbed:~$ mv test.sh ~/bin/ earley@testbed:~$ echo $PATH /home/earley/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/ usr/bin:/sbin:/bin:/usr/bin/X11 earley@testbed:~$ test.sh -bash: /home/earley/bin/test.sh: Permission denied earley@testbed:~$ • Move the shell script into a directory in the path • Try and execute it again • Now we get “Permission denied”! Why!?!? © 2018 Rogue Wave Software, Inc. All Rights Reserved. 23 Running Your Shell Script earley@testbed:~$ ls –l ~/bin/test.sh -rw-r--r-- 1 earley earley 32 2006-09-11 08:54 /home/earley/bin/test.sh earley@testbed:~$ chmod u+x ~/bin/test.sh earley@testbed:~$ ls –l ~/bin/test.sh -rwx--r-- 1 earley earley 32 2006-09-11 08:54 /home/earley/bin/test.sh earley@testbed:~$ test.sh Hello World earley@testbed:~$ • The file is not marked with "executable" permissions • "chmod u+x …" says "make it executable by the user who owns it" • NOW it works © 2018 Rogue Wave Software, Inc.
Recommended publications
  • 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]
  • 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]
  • The GNOME Desktop Environment
    The GNOME desktop environment Miguel de Icaza ([email protected]) Instituto de Ciencias Nucleares, UNAM Elliot Lee ([email protected]) Federico Mena ([email protected]) Instituto de Ciencias Nucleares, UNAM Tom Tromey ([email protected]) April 27, 1998 Abstract We present an overview of the free GNU Network Object Model Environment (GNOME). GNOME is a suite of X11 GUI applications that provides joy to users and hackers alike. It has been designed for extensibility and automation by using CORBA and scripting languages throughout the code. GNOME is licensed under the terms of the GNU GPL and the GNU LGPL and has been developed on the Internet by a loosely-coupled team of programmers. 1 Motivation Free operating systems1 are excellent at providing server-class services, and so are often the ideal choice for a server machine. However, the lack of a consistent user interface and of consumer-targeted applications has prevented free operating systems from reaching the vast majority of users — the desktop users. As such, the benefits of free software have only been enjoyed by the technically savvy computer user community. Most users are still locked into proprietary solutions for their desktop environments. By using GNOME, free operating systems will have a complete, user-friendly desktop which will provide users with powerful and easy-to-use graphical applications. Many people have suggested that the cause for the lack of free user-oriented appli- cations is that these do not provide enough excitement to hackers, as opposed to system- level programming. Since most of the GNOME code had to be written by hackers, we kept them happy: the magic recipe here is to design GNOME around an adrenaline response by trying to use exciting models and ideas in the applications.
    [Show full text]
  • Ardpower Documentation Release V1.2.0
    ardPower Documentation Release v1.2.0 Anirban Roy Das Sep 27, 2017 Contents 1 Introduction 1 2 Screenshot 3 3 Documentaion 5 3.1 Overview.................................................5 3.2 Installation................................................7 3.3 Usage................................................... 12 4 Indices and tables 13 i ii CHAPTER 1 Introduction Its a custom Oh-My-Zsh Theme inspired by many custom themes suited for a perfect ZSH Environment under Byobu with Tmux Backend. 1 ardPower Documentation, Release v1.2.0 2 Chapter 1. Introduction 3 ardPower Documentation, Release v1.2.0 CHAPTER 2 Screenshot 4 Chapter 2. Screenshot CHAPTER 3 Documentaion You can also find PDF version of the documentation here. Overview We will start with understanding the individual components of an entire CLI. Generally we don’t put much attention to what we do. We just fire up a terminal or some say sheel and start typing our commands and get the result. That’s all. But there are a lot of things that goes behind all this. Terminal The very first component is the Terminal. So what is a Terminal? A terminal emulator, terminal application, term, or tty for short, is a program that emulates a video ter- minal within some other display architecture. Though typically synonymous with a shell or text terminal, the term terminal covers all remote terminals, including graphical interfaces. A terminal emulator inside a graphical user interface is often called a terminal window.A terminal window allows the user access to a text terminal and all its applications such as command-line interfaces (CLI) and text user interface (TUI) applications.
    [Show full text]
  • Development Version from Github
    Qtile Documentation Release 0.13.0 Aldo Cortesi Dec 24, 2018 Contents 1 Getting started 1 1.1 Installing Qtile..............................................1 1.2 Configuration...............................................4 2 Commands and scripting 21 2.1 Commands API............................................. 21 2.2 Scripting................................................. 24 2.3 qshell................................................... 24 2.4 iqshell.................................................. 26 2.5 qtile-top.................................................. 27 2.6 qtile-run................................................. 27 2.7 qtile-cmd................................................. 27 2.8 dqtile-cmd................................................ 30 3 Getting involved 33 3.1 Contributing............................................... 33 3.2 Hacking on Qtile............................................. 35 4 Miscellaneous 39 4.1 Reference................................................. 39 4.2 Frequently Asked Questions....................................... 98 4.3 License.................................................. 99 i ii CHAPTER 1 Getting started 1.1 Installing Qtile 1.1.1 Distro Guides Below are the preferred installation methods for specific distros. If you are running something else, please see In- stalling From Source. Installing on Arch Linux Stable versions of Qtile are currently packaged for Arch Linux. To install this package, run: pacman -S qtile Please see the ArchWiki for more information on Qtile. Installing
    [Show full text]
  • Unix Systems: Shell Scripting (III)
    Unix Systems: Shell Scripting (III) Bruce Beckles University of Cambridge Computing Service 1 Introduction • Who: ! Bruce Beckles, e-Science Specialist, UCS • What: ! Unix Systems: Shell Scripting (III) course ! Follows on from “Unix Systems: Shell Scripting (II)” ! Part of the Scientific Computing series of courses • Contact (questions, etc): ! [email protected] • Health & Safety, etc: ! Fire exits • Please switch off mobile phones! [email protected] Unix Systems: Shell Scripting (III) 2 As this course is part of the Scientific Computing series of courses run by the Computing Service, all the examples that we use will be more relevant to scientific computing than to system administration, etc. This does not mean that people who wish to learn shell scripting for system administration and other such tasks will get nothing from this course, as the techniques and underlying knowledge taught are applicable to shell scripts written for almost any purpose. However, such individuals should be aware that this course was not designed with them in mind. For details of the “Unix Systems: Shell Scripting (II)” course, see: http://www.cam.ac.uk/cs/courses/coursedesc/linux.html#script2 2 What we don’t cover • Different types of shell: ! We are using the Bourne-Again SHell (bash). • Differences between versions of bash • Very advanced shell scripting – try this course instead: ! “Programming: Python for Absolute Beginners” [email protected] Unix Systems: Shell Scripting (III) 3 bash is probably the most common shell on modern Unix/Linux systems – in fact, on most modern Linux distributions it will be the default shell (the shell users get if they don’t specify a different one).
    [Show full text]
  • Lab Work 06. Linux Shell. Files Globbing & Streams Redirection
    LAB WORK 06. LINUX SHELL. FILES GLOBBING & STREAMS REDIRECTION. 1. PURPOSE OF WORK • Learn to use shell file globbing (wildcard); • Learn basic concepts about standard UNIX/Linux streams redirections; • Acquire skills of working with filter-programs. • Get experience in creating composite commands that have a different functional purpose than the original commands. 2. TASKS FOR WORK NOTE. Start Your UbuntuMini Virtual Machine on your VirtualBox. You need only Linux Terminal to complete the lab tasks. Before completing the tasks, make a Snapshot of your Virtual Linux. If there are problems, you can easily go back to working condition! 2.0. Create new User account for this Lab Work. • Login as student account (user with sudo permissions). • Create new user account, example stud. Use adduser command. (NOTE. You can use the command “userdel –rf stud” to delete stud account from your Linux.) $ sudo adduser stud • Logout from student account (logout) and login as stud. 2.1. Shell File Globbing Study. 2.2. File Globbing Practice. (Fill in a Table 1 and Table 2) 2.3. Command I/O Redirection Study. 2.4. Redirection Practice. (Fill in a Table 3 and Table 4) © Yuriy Shamshin, 2021 1/20 3. REPORT Make a report about this work and send it to the teacher’s email (use a docx Report Blank). REPORT FOR LAB WORK 06: LINUX SHELL. FILES GLOBBING & STREAMS REDIRECTION Student Name Surname Student ID (nV) Date 3.1. Insert Completing Table 1. File globbing understanding. 3.2. Insert Completing Table 2. File globbing creation. 3.3. Insert Completing Table 3. Command I/O redirection understanding.
    [Show full text]
  • Linux: Come E Perchх
    ÄÒÙÜ Ô ©2007 mcz 12 luglio 2008 ½º I 1. Indice II ½º Á ¾º ¿º ÈÖÞÓÒ ½ º È ÄÒÙÜ ¿ º ÔÔÖÓÓÒÑÒØÓ º ÖÒÞ ×ÓרÒÞÐ ÏÒÓÛ× ¾½ º ÄÒÙÜ ÕÙÐ ×ØÖÙÞÓÒ ¾ º ÄÒÙÜ ÀÖÛÖ ×ÙÔÔ ÓÖØØÓ ¾ º È Ð ÖÒÞ ØÖ ÖÓ ÓØ Ù×Ö ¿½ ½¼º ÄÒÙÜ × ÒרÐÐ ¿¿ ½½º ÓÑ × ÒרÐÐÒÓ ÔÖÓÖÑÑ ¿ ½¾º ÒÓÒ ØÖÓÚÓ ÒÐ ×ØÓ ÐÐ ×ØÖÙÞÓÒ ¿ ½¿º Ó׳ ÙÒÓ ¿ ½º ÓÑ × Ð ××ØÑ ½º ÓÑ Ð ½º Ð× Ñ ½º Ð Ñ ØÐ ¿ ½º ÐÓ ½º ÓÑ × ÒרÐÐ Ð ×ØÑÔÒØ ¾¼º ÓÑ ÐØØÖ¸ Ø×Ø ÐÖ III Indice ¾½º ÓÑ ÚÖ Ð ØÐÚ×ÓÒ ¿ 21.1. Televisioneanalogica . 63 21.2. Televisione digitale (terrestre o satellitare) . ....... 64 ¾¾º ÐÑØ ¾¿º Ä 23.1. Fotoritocco ............................. 67 23.2. Grafica3D.............................. 67 23.3. Disegnovettoriale-CAD . 69 23.4.Filtricoloreecalibrazionecolori . .. 69 ¾º ×ÖÚ Ð ½ 24.1.Vari.................................. 72 24.2. Navigazionedirectoriesefiles . 73 24.3. CopiaCD .............................. 74 24.4. Editaretesto............................. 74 24.5.RPM ................................. 75 ¾º ×ÑÔ Ô ´ËÐе 25.1.Montareundiscoounapenna . 77 25.2. Trovareunfilenelsistema . 79 25.3.Vedereilcontenutodiunfile . 79 25.4.Alias ................................. 80 ¾º × ÚÓÐ×× ÔÖÓÖÑÑÖ ½ ¾º ÖÓÛ×Ö¸ ÑÐ ººº ¿ ¾º ÖÛÐÐ Ð³ÒØÚÖÙ× Ð ÑØØÑÓ ¾º ÄÒÙÜ ½ ¿¼º ÓÑ ØÖÓÚÖ ÙØÓ ÖÖÑÒØ ¿ ¿½º Ð Ø×ØÙÐ Ô Ö Ð ×ØÓÔ ÄÒÙÜ ¿¾º ´ÃµÍÙÒØÙ¸ ÙÒ ×ØÖÙÞÓÒ ÑÓÐØÓ ÑØ ¿¿º ËÙÜ ÙÒ³ÓØØÑ רÖÙÞÓÒ ÄÒÙÜ ½¼½ ¿º Á Ó Ò ÄÒÙÜ ½¼ ¿º ÃÓÒÕÙÖÓÖ¸ ÕÙ×ØÓ ½¼ ¿º ÃÓÒÕÙÖÓÖ¸ Ñ ØÒØÓ Ô Ö ½½¿ 36.1.Unaprimaocchiata . .114 36.2.ImenudiKonqueror . .115 36.3.Configurazione . .116 IV Indice 36.4.Alcuniesempidiviste . 116 36.5.Iservizidimenu(ServiceMenu) . 119 ¿º ÃÓÒÕÙÖÓÖ Ø ½¾¿ ¿º à ÙÒ ÖÖÒØ ½¾ ¿º à ÙÒ ÐÙ×ÓÒ ½¿½ ¼º ÓÒÖÓÒØÓ ÒרÐÐÞÓÒ ÏÒÓÛ×È ÃÍÙÒØÙ º½¼ ½¿¿ 40.1.
    [Show full text]
  • Korn Shell Variables
    V4.1 cover Front cover Korn and Bash Shell Programming (Course code AL32) Student Notebook ERC 1.0 IBM Certified Course Material Student Notebook Trademarks IBM® is a registered trademark of International Business Machines Corporation. The following are trademarks of International Business Machines Corporation in the United States, or other countries, or both: AIX® AIX 5L™ Language Environment® OS/2® POWER™ RISC System/6000® RS/6000® Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. Windows is a trademark of Microsoft Corporation in the United States, other countries, or both. UNIX® is a registered trademark of The Open Group in the United States and other countries. Linux® is a registered trademark of Linus Torvalds in the United States, other countries, or both. Other company, product, or service names may be trademarks or service marks of others. October 2007 edition The information contained in this document has not been submitted to any formal IBM test and is distributed on an “as is” basis without any warranty either express or implied. The use of this information or the implementation of any of these techniques is a customer responsibility and depends on the customer’s ability to evaluate and integrate them into the customer’s operational environment. While each item may have been reviewed by IBM for accuracy in a specific situation, there is no guarantee that the same or similar results will result elsewhere. Customers attempting to adapt these techniques to their own environments do so at their own risk. © Copyright International Business Machines Corporation 2007.
    [Show full text]
  • Scripting the Openssh, SFTP, and SCP Utilities on I Scott Klement
    Scripting the OpenSSH, SFTP, and SCP Utilities on i Presented by Scott Klement http://www.scottklement.com © 2010-2015, Scott Klement Why do programmers get Halloween and Christmas mixed-up? 31 OCT = 25 DEC Objectives Of This Session • Setting up OpenSSH on i • The OpenSSH tools: SSH, SFTP and SCP • How do you use them? • How do you automate them so they can be run from native programs (CL programs) 2 What is SSH SSH is short for "Secure Shell." Created by: • Tatu Ylönen (SSH Communications Corp) • Björn Grönvall (OSSH – short lived) • OpenBSD team (led by Theo de Raadt) The term "SSH" can refer to a secured network protocol. It also can refer to the tools that run over that protocol. • Secure replacement for "telnet" • Secure replacement for "rcp" (copying files over a network) • Secure replacement for "ftp" • Secure replacement for "rexec" (RUNRMTCMD) 3 What is OpenSSH OpenSSH is an open source (free) implementation of SSH. • Developed by the OpenBSD team • but it's available for all major OSes • Included with many operating systems • BSD, Linux, AIX, HP-UX, MacOS X, Novell NetWare, Solaris, Irix… and yes, IBM i. • Integrated into appliances (routers, switches, etc) • HP, Nokia, Cisco, Digi, Dell, Juniper Networks "Puffy" – OpenBSD's Mascot The #1 SSH implementation in the world. • More than 85% of all SSH installations. • Measured by ScanSSH software. • You can be sure your business partners who use SSH will support OpenSSH 4 Included with IBM i These must be installed (all are free and shipped with IBM i **) • 57xx-SS1, option 33 = PASE • 5733-SC1, *BASE = Portable Utilities • 5733-SC1, option 1 = OpenSSH, OpenSSL, zlib • 57xx-SS1, option 30 = QShell (useful, not required) ** in v5r3, had 5733-SC1 had to be ordered separately (no charge.) In v5r4 or later, it's shipped automatically.
    [Show full text]
  • Bash Tutorial
    Bash Shell Lecturer: Prof. Andrzej (AJ) Bieszczad Email: [email protected] Phone: 818-677-4954 Bash Shell The shell of Linux • Linux has a variety of different shells: – Bourne shell (sh), C shell (csh), Korn shell (ksh), TC shell (tcsh), Bour ne Again shell (bash). • Certainly the most popular shell is “bash”. Bash is an sh- compatible shell that incorporates useful features from the Korn shell (ksh) and C shell (csh). • It is intended to conform to the IEEE POSIX P1003.2/ISO 9945.2 Shell and Tools standard. • It offers functional improvements over sh for both programming and interactive use. Bash Shell Programming or Scripting ? • bash is not only an excellent command line shell, but a scripting language in itself. Shell scripting allows us to use the shell's abilities and to automate a lot of tasks that would otherwise require a lot of commands. • Difference between programming and scripting languages: – Programming languages are generally a lot more powerful and a lot faster than scriptin g languages. Programming languages generally start from source code and are compil ed into an executable. This executable is not easily ported into different operating syste ms. – A scripting language also starts from source code, but is not compiled into an executabl e. Rather, an interpreter reads the instructions in the source file and executes each inst ruction. Interpreted programs are generally slower than compiled programs. The main a dvantage is that you can easily port the source file to any operating system. bash is a s cripting language. Other examples of scripting languages are Perl, Lisp, and Tcl.
    [Show full text]
  • CS2043 - Unix Tools & Scripting Cornell University, Spring 20141
    CS2043 - Unix Tools & Scripting Cornell University, Spring 20141 Instructor: Bruno Abrahao January 31, 2014 1 Slides evolved from previous versions by Hussam Abu-Libdeh and David Slater Instructor: Bruno Abrahao CS2043 - Unix Tools & Scripting Vim: Tip of the day! Line numbers Displays line number in Vim: :set nu Hides line number in Vim: :set nonu Goes to line number: :line number Instructor: Bruno Abrahao CS2043 - Unix Tools & Scripting Counting wc How many lines of code are in my new awesome program? How many words are in this document? Good for bragging rights Word, Character, Line, and Byte count with wc wc -l : count the number of lines wc -w : count the number of words wc -m : count the number of characters wc -c : count the number of bytes Instructor: Bruno Abrahao CS2043 - Unix Tools & Scripting Sorting sort Sorts the lines of a text file alphabetically. sort -ru file sorts the file in reverse order and deletes duplicate lines. sort -n -k 2 -t : file sorts the file numerically by using the second column, separated by a colon Example Consider a file (numbers.txt) with the numbers 1, 5, 8, 11, 62 each on a separate line, then: $ sort numbers.txt $ sort numbers.txt -n 1 1 11 5 5 8 62 11 8 62 Instructor: Bruno Abrahao CS2043 - Unix Tools & Scripting uniq uniq uniq file - Discards all but one of successive identical lines uniq -c file - Prints the number of successive identical lines next to each line Instructor: Bruno Abrahao CS2043 - Unix Tools & Scripting Character manipulation! The Translate Command tr [options] <char_list1> [char_list2] Translate or delete characters char lists are strings of characters By default, searches for characters in char list1 and replaces them with the ones that occupy the same position in char list2 Example: tr 'AEIOU' 'aeiou' - changes all capital vowels to lower case vowels Instructor: Bruno Abrahao CS2043 - Unix Tools & Scripting Pipes and redirection tr only receives input from standard input (stdin) i.e.
    [Show full text]