A User's Guide to the Z-Shell

Total Page:16

File Type:pdf, Size:1020Kb

A User's Guide to the Z-Shell A User’s Guide to the Z-Shell Peter Stephenson 2003/03/23 2 Contents 1 A short introduction 11 1.1 Other shells and other guides . 12 1.2 Versions of zsh . 13 1.3 Conventions . 14 1.4 Acknowledgments . 15 2 What to put in your startup files 17 2.1 Types of shell: interactive and login shells . 17 2.1.1 What is a login shell? Simple tests . 18 2.2 All the startup files . 19 2.3 Options . 21 2.4 Parameters . 21 2.4.1 Arrays . 23 2.5 What to put in your startup files . 24 2.5.1 Compatibility options: SH_WORD_SPLIT and others . 24 2.5.2 Options for csh junkies . 32 2.5.3 The history mechanism: types of history . 34 2.5.4 Setting up history . 36 2.5.5 History options . 37 2.5.6 Prompts . 39 2.5.7 Named directories . 42 2.5.8 ‘Go faster’ options for power users . 43 2.5.9 aliases . 45 2.5.10 Environment variables . 46 3 4 CONTENTS 2.5.11 Path . 47 2.5.12 Mail . 48 2.5.13 Other path-like things . 49 2.5.14 Version-specific things . 50 2.5.15 Everything else . 50 3 Dealing with basic shell syntax 51 3.1 External commands . 51 3.2 Builtin commands . 53 3.2.1 Builtins for printing . 53 3.2.2 Other builtins just for speed . 56 3.2.3 Builtins which change the shell’s state . 57 3.2.4 cd and friends . 59 3.2.5 Command control and information commands . 65 3.2.6 Parameter control . 68 3.2.7 History control commands . 80 3.2.8 Job control and process control . 80 3.2.9 Terminals, users, etc. 89 3.2.10 Syntactic oddments . 89 3.2.11 More precommand modifiers: exec, noglob . 92 3.2.12 Testing things . 93 3.2.13 Handling options to functions and scripts . 96 3.2.14 Random file control things . 98 3.2.15 Don’t watch this space, watch some other . 99 3.2.16 And also . 100 3.3 Functions . 100 3.3.1 Loading functions . 100 3.3.2 Function parameters . 102 3.3.3 Compiling functions . 108 3.4 Aliases . 113 3.5 Command summary . 115 3.6 Expansions and quotes . 116 CONTENTS 5 3.6.1 History expansion . 116 3.6.2 Alias expansion . 117 3.6.3 Process, parameter, command, arithmetic and brace expansion . 117 3.6.4 Filename Expansion . 123 3.6.5 Filename Generation . 126 3.7 Redirection: greater-thans and less-thans . 128 3.7.1 Clobber . 129 3.7.2 File descriptors . 129 3.7.3 Appending, here documents, here strings, read write . 131 3.7.4 Clever tricks: exec and other file descriptors . 132 3.7.5 Multios . 133 3.8 Shell syntax: loops, (sub)shells and so on . 134 3.8.1 Logical command connectors . 134 3.8.2 Structures . 136 3.8.3 Subshells and current shell constructs . 139 3.8.4 Subshells and current shells . 140 3.9 Emulation and portability . 142 3.9.1 Differences in detail . 142 3.9.2 Making your own scripts and functions portable . 144 3.10 Running scripts . 145 4 The Z-Shell Line Editor 149 4.1 Introducing zle . 149 4.1.1 The simple facts . 150 4.1.2 Vi mode . 151 4.2 Basic editing . 152 4.2.1 Moving . 152 4.2.2 Deleting . 152 4.2.3 More deletion . 154 4.3 Fancier editing . 154 4.3.1 Options controlling zle . 154 4.3.2 The minibuffer and extended commands . 155 6 CONTENTS 4.3.3 Prefix (digit) arguments . 156 4.3.4 Words, regions and marks . 156 4.3.5 Regions and marks . 157 4.4 History and searching . 158 4.4.1 Moving through the history . 158 4.4.2 Searching through the history . 159 4.4.3 Extracting words from the history . 161 4.5 Binding keys and handling keymaps . 161 4.5.1 Simple key bindings . 161 4.5.2 Removing key bindings . 162 4.5.3 Function keys and so on . 163 4.5.4 Binding strings instead of commands . 164 4.5.5 Keymaps . 165 4.6 Advanced editing . 166 4.6.1 Multi-line editing . 166 4.6.2 The builtin vared and the function zed . 168 4.6.3 The buffer stack . 169 4.7 Extending zle . 170 4.7.1 Widgets . 170 4.7.2 Executing other widgets . 171 4.7.3 Some special builtin widgets and their uses . ..
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]
  • Cygwin User's Guide
    Cygwin User’s Guide Cygwin User’s Guide ii Copyright © Cygwin authors Permission is granted to make and distribute verbatim copies of this documentation provided the copyright notice and this per- mission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this documentation under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this documentation into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Free Software Foundation. Cygwin User’s Guide iii Contents 1 Cygwin Overview 1 1.1 What is it? . .1 1.2 Quick Start Guide for those more experienced with Windows . .1 1.3 Quick Start Guide for those more experienced with UNIX . .1 1.4 Are the Cygwin tools free software? . .2 1.5 A brief history of the Cygwin project . .2 1.6 Highlights of Cygwin Functionality . .3 1.6.1 Introduction . .3 1.6.2 Permissions and Security . .3 1.6.3 File Access . .3 1.6.4 Text Mode vs. Binary Mode . .4 1.6.5 ANSI C Library . .4 1.6.6 Process Creation . .5 1.6.6.1 Problems with process creation . .5 1.6.7 Signals . .6 1.6.8 Sockets . .6 1.6.9 Select . .7 1.7 What’s new and what changed in Cygwin . .7 1.7.1 What’s new and what changed in 3.2 .
    [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]
  • A Brief Introduction to the Use of Shell Variables
    A Brief Introduction to the Use of Shell Variables Norman Matloff July 25, 2001 Contents 1 Two Popular Shells: tcsh and bash 1.1 Overview There are many different shells available for Unix systems. Here we focus on two of the most popular ones, tcsh and bash. Other shells tend to be very similar to one or both of these. Your Unix account has a preset login shell for you, typically tcsh in academic settings and bash in Linux. When you log in, a shell of the given type is automatically started for you. (This can be seen in the file /etc/passwd.) If you wish to temporarily run a different shell, just type its name. If you wish to change your login shell, run the chsh command. 1.2 Command Commonality Among Shells Most of what people tend to think of as “basic Unix commands” are actually shell commands which are common to almost all of the shells. So for example you could type cd /abc/def to change to the directory /abc/def in either tcsh or bash.1 2 Shell Variables 2.1 Introduction to Shell Variable Syntax The tcsh shell uses “set” and = for the assignment operation. For example, 1Technically speaking, the “change directory” command for Unix itself is chdir(), a function which must be called from a program. A shell is a program, and when for example you issue the cd command to a shell, that program in turn calls chdir(). 1 set x = 3 would assign the value 3 to the shell variable x.
    [Show full text]
  • Shell Variables
    Shell Using the command line Orna Agmon ladypine at vipe.technion.ac.il Haifux Shell – p. 1/55 TOC Various shells Customizing the shell getting help and information Combining simple and useful commands output redirection lists of commands job control environment variables Remote shell textual editors textual clients references Shell – p. 2/55 What is the shell? The shell is the wrapper around the system: a communication means between the user and the system The shell is the manner in which the user can interact with the system through the terminal. The shell is also a script interpreter. The simplest script is a bunch of shell commands. Shell scripts are used in order to boot the system. The user can also write and execute shell scripts. Shell – p. 3/55 Shell - which shell? There are several kinds of shells. For example, bash (Bourne Again Shell), csh, tcsh, zsh, ksh (Korn Shell). The most important shell is bash, since it is available on almost every free Unix system. The Linux system scripts use bash. The default shell for the user is set in the /etc/passwd file. Here is a line out of this file for example: dana:x:500:500:Dana,,,:/home/dana:/bin/bash This line means that user dana uses bash (located on the system at /bin/bash) as her default shell. Shell – p. 4/55 Starting to work in another shell If Dana wishes to temporarily use another shell, she can simply call this shell from the command line: [dana@granada ˜]$ bash dana@granada:˜$ #In bash now dana@granada:˜$ exit [dana@granada ˜]$ bash dana@granada:˜$ #In bash now, going to hit ctrl D dana@granada:˜$ exit [dana@granada ˜]$ #In original shell now Shell – p.
    [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]
  • Php Tutorial
    PHP About the Tutorial The PHP Hypertext Preprocessor (PHP) is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web-based software applications. This tutorial will help you understand the basics of PHP and how to put it in practice. Audience This tutorial has been designed to meet the requirements of all those readers who are keen to learn the basics of PHP. Prerequisites Before proceeding with this tutorial, you should have a basic understanding of computer programming, Internet, Database, and MySQL. Copyright & Disclaimer © Copyright 2016 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at [email protected] i PHP Table of Contents About the Tutorial ...........................................................................................................................................
    [Show full text]
  • UNIX Essentials (Hands-On)
    UNIX essentials (hands-on) • the directory tree • running programs • the shell (using the T-shell) → command line processing → special characters → command types → shell variables → environment variables → wildcards → shell scripts → shell commands → pipes and redirection • OS commands • special files 1 • The Directory Tree → directories contain files and/or directories → / : means either the root directory, or a directory separator • consider /home/afniuser/AFNI_data3 afniuser/suma_demo → an "absolute" pathname begins with '/', a "relative" pathname does not • a relative pathname depends on where you start from • in the directories above, note which is a relative pathname → every directory has a parent directory • the relative pathname for the parent directory is '..' • the relative pathname for the current directory is '.' • consider './run_this_script' and '/bin/ls ../../suma_demo' → many commands can be used to return to the home directory (of "afniuser") • cd, cd ~, cd ~afniuser, cd $HOME, cd /home/afniuser • note the 2 special characters, '~' and '$' → while you work, keep your location within the directory tree in mind 2 → class work: • open a terminal window • commands: cd, pwd, ls, ls -al • use the "cd" command to go to the given directories e.g. for directory /usr/bin, use the command: cd /usr/bin once there, use the commands "pwd", "ls", and "ls -al" note that you can always return to the home directory via: cd / home/afniuser AFNI_data3 .. AFNI_data3/afni /usr/bin ~/abin ../../afniuser/../afniuser • first example (starting with the '/'directory), use the commands: cd / pwd ls ls -al 3 • Running Programs → a program is something that gets "executed", or "run" → the first element of a command line is generally a program (followed by a space) → most shells are case sensitive when processing a command → command examples: /bin/ls $HOME ~/AFNI_data3 count -digits 2 1 10 → script: an interpreted program (interpreted by another program) • e.g.
    [Show full text]
  • Bash Guide for Beginners
    Bash Guide for Beginners Machtelt Garrels Garrels BVBA <tille wants no spam _at_ garrels dot be> Version 1.11 Last updated 20081227 Edition Bash Guide for Beginners Table of Contents Introduction.........................................................................................................................................................1 1. Why this guide?...................................................................................................................................1 2. Who should read this book?.................................................................................................................1 3. New versions, translations and availability.........................................................................................2 4. Revision History..................................................................................................................................2 5. Contributions.......................................................................................................................................3 6. Feedback..............................................................................................................................................3 7. Copyright information.........................................................................................................................3 8. What do you need?...............................................................................................................................4 9. Conventions used in this
    [Show full text]
  • Unix Tools 1 Jeff Freymueller Resources
    Unix Tools 1 Jeff Freymueller Resources • Unix and Linux – It comes with the package • Macintosh – Really a Unix machine with fancy wrapping – Terminal.app • Windows – VirtualBox: hFp://www.virtualbox.org/ – Or you could try Cygwin: hFp://www.cygwin.com/ Outline • What is Unix, what is the shell? • Directories, files, wildcards • RedirecPng input/output, pipes • Variables and control • Power tools: GMT, etc. in future lectures • Need more power? Upgrade to perl! • perl = PracPcal ExtracPon and ReporPng Language • perl = Pathologically Extensible Rubbish Lister! Unix • Unix is the most common operang system for “serious computers” – Developed in 1969 at Bell Labs (of the old AT&T) – At first, could support two simultaneous users! – RewriFen in C in 1973 (before that, assembly language) • From Wikipedia: – Unix was designed to be portable, mulP-tasking and mulP-user in a Pme-sharing configuraon. Unix systems are characterized by various concepts: the use of plain text for storing data; a hierarchical file system; treang devices and certain types of inter-process communicaon (IPC) as files; and the use of a large number of sodware tools, small programs that can be strung together through a command line interpreter using pipes, as opposed to using a single monolithic program that includes all of the same func6onality. These concepts are known as the Unix philosophy. Unix, Unices, Linux • Numerous Unix variants have sprung up over the years, some academic and some commercial. – BSD, Solaris, HP-UX, … – Linux is unix-like, not Unix • Started as a hobby project by Linus Torvalds • Made useful by existence of free, open source sodware tools (like the Gnu project) • OS consists of two major parts: kernel and everything else – Kernel: master control program, starts and stops processes, handles low-level file/disk access, etc.
    [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]
  • A Common Framework for Scripting Tutorials Erik Hjelmås and Ivar
    A Common Framework for Scripting Tutorials Erik Hjelmås and Ivar Farup Abstract A scripting tutorial should focus on teaching the characteristics of scripting languages, avoiding the pitfall of teaching only syntax conversion from system programming languages. Examples should be selected to emphasize features of scripting languages in general (e.g. weak typing, associate arrays, “gluing”) and the scripting language at hand. Students might benefit from using the same framework (structure of programming elements and examples) for learning multiple scripting languages. Their existing programming skills should be reused while newly introduced scripting concepts should be reinforced in subsequent examples. 1 Introduction Scripting languages are popular for solving problems in many different domains [8]. Some are general scripting languages such as Perl, Python and Ruby, while others are slightly domain-specific (platform-specific: Bash, PowerShell) or very domain-specific (application-specific: Cfengine, Matlab). They can be characterized as high-level and weakly typed, as opposed to system programming languages such as Java and C++ [11]. In higher education, scripting languages are used both for introductory programming courses [14] and for lab exercises in later courses. It is in this last context the present work seeks to contribute to a better learning experience for students. Although much effort has been invested in researching ways of teaching introductory programming [12], the problem of how to convert existing programming skills to a new language seems slightly overlooked. The way this is solved in practice is by either providing a short tutorial style introduction to the new language, or referring the student to an online tutorial resource.
    [Show full text]