CSE 374 Programming Concepts & Tools

Slides:



Advertisements
Similar presentations
Lecture 4 Shell environment III: - command alias & history; - job control; - editor (vim) CSE4251 The Unix Programming Environment 1.
Advertisements

1 © 2001 John Urrutia. All rights reserved. Chapter 5 The Shell Overview.
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
Linux+ Guide to Linux Certification, Second Edition
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
Linux+ Guide to Linux Certification, Second Edition
23-Jun-15Advanced Programming Spring 2002 bash Henning Schulzrinne Department of Computer Science Columbia University.
Guide To UNIX Using Linux Third Edition
Introduction to Linux and Shell Scripting Jacob Chan.
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.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Shell The Shell The agency that.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
The UNIX Shell. The Shell Program that constantly runs at terminal after a user has logged in. Prompts the user and waits for user input. Interprets command.
CS 2061 Shells Also known as: Unix Command Interpreter.
Shell Scripting Todd Kelley CST8207 – Todd Kelley1.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Linux+ Guide to Linux Certification, Third Edition
Basic Shell Scripting - Part 1 Objective - Learn to: Read Start-up Files Edit Start-up Files Modify Your User Environment Communicate with Users Write.
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
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.
1 CSE 303 Lecture 3 bash shell continued: processes; multi-user systems; combining commands read Linux Pocket Guide pp , , , 118, 122,
40 Years and Still Rocking the Terminal!
UNIX shell environments CS 2204 Class meeting 6 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 2 – Processes, Programs, the Shell (& emacs)
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Linux+ Guide to Linux Certification, Second Edition
Introduction to Bash Shell. What is Shell? The shell is a command interpreter. It is the layer between the operating system kernel and the user.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2014 Lecture 3 – I/O Redirection, Shell Scripts.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
1 CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
Linux Administration Working with the BASH Shell.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Using Linux Kaya Oğuz Room: 310.
Introduction to the Linux Command Line Interface Research Computing Systems Bob Torgerson July 19, 2016.
CSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools
slides created by Marty Stepp, modified by Josh Goodwin
Introduction to Shells
Shell Features CSCI N321 – System and Network Administration
Bash Introduction (adapted from chapters 1 and 2 of bash Cookbook by Albing, Vossing, & Newham) CPTE 440 John Beckett.
CSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools
The Linux Operating System
stdin, stdout, stderr Redirection
CSE 303 Concepts and Tools for Software Development
Basic UNIX OLC Training.
LING 408/508: Computational Techniques for Linguists
LING 408/508: Computational Techniques for Linguists
CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
slides created by Marty Stepp, modified by Jessica Miller
Introduction Paul Flynn
Shell Programming.
CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
CSE 303 Concepts and Tools for Software Development
Linux Shell Script Programming
slides created by Marty Stepp, modified by Jessica Miller
CSE 391 Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
CSE 303 Concepts and Tools for Software Development
CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
CSE 391 Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
Introduction to Bash Programming, part 3
Presentation transcript:

CSE 374 Programming Concepts & Tools Hal Perkins Fall 2017 Lecture 2 – Processes, Programs, the Shell (& emacs) UW CSE 374 Fall 2017

News HW0 due tonight if you’re not already done Any lingering account/VM issues? HW1 out now, due Thursday night, 11 pm Linux commands, files, editing Please use discussion board, or mail to cse374-staff when email is needed; not mail to individual TAs/instructor Remember to post a followup message on the discussion board if you haven’t already Be sure to work with colleagues and help each other out (discussion board, study groups, etc.). Just be sure not to trade actual hw solutions (see academic integrity policy) UW CSE 374 Fall 2017

Where we are It’s like we started over using the computer from scratch All we can do is run dinky programs at the command-line But we are learning a model (a system is files, processes, and users) and a powerful way to control it (the shell) If we get the model right, hopefully we can learn lots of details quickly Today: The rest of the model briefly: Processes and Users More programs (ps, chmod, kill, . . . ) Special shell characters (*, ~, . . . ) Text editing (particularly emacs) UW CSE 374 Fall 2017

Users There is one file-system, one operating system, one or more CPUs, and multiple users whoami ls -l and chmod (permissions), quota (limits) Make your homework unreadable by others! /etc/passwd (or equivalent) guides the login program: Correct username and (originally) password – actual encrypted password is elsewhere now for security Home directory Which shell to open (pass it the home directory) The shell then takes over, with startup scripts (e.g., .bash_profile, .bashrc). (ls -a) One “superuser” a.k.a. root. (Change passwords, halt machine, change system directories, add/remove user accounts, . . . ) UW CSE 374 Fall 2017

Programs & the Shell A program is a file that can be executed Almost all system commands are programs The shell is itself a program Reads lines you type in & carries them out Normally finds the named program and runs it A few commands are shell “built-ins” that the shell executes itself because they change the state of the shell. Obvious example: cd After the named program runs it exits and the shell reads the next command More to this story to come… UW CSE 374 Fall 2017

Processes A running program is called a process. An application (e.g., emacs), may be running as 0, 1, or 57 processes at any time The shell runs a program by “launching a process” waiting for it to finish, and giving you your prompt back. What you want for ls, but not for emacs. &, jobs, fg, bg, kill — job control ps, top Each process has private memory and I/O streams A running shell is just a process that kills itself when interpreting the exit command (Apologies for aggressive vocabulary, but we’re stuck with it for now.) UW CSE 374 Fall 2017

Standard I/O streams Every process has 3 standard streams: stdin (input), stdout (output), stderr (error messages) Default is keyboard (stdin), terminal window (stdout, stderr) Default behavior is to read from stdin, write normal output to stdout, write diagnostic output to stderr Many programs accept command-line arguments naming files to read If not supplied, just read stdin Also ways to redirect stdin, stdout, stderr. Later… UW CSE 374 Fall 2017

That’s most of a running system File-system, users, processes The operating system manages these Processes can do I/O, change files, launch other processes. Other things: Input/Output devices (monitor, keyboard, network) GUIs don’t change any of this, but they do hide it a bit Now: Back to the shell. . . UW CSE 374 Fall 2017

The shell so far So far, our view of the shell is the barest minimum: builtins affect subsequent interpretations New builtin: source Otherwise, the first “word” is a program run with the other “words” passed as arguments Programs interpret arguments arbitrarily, but conventions exist UW CSE 374 Fall 2017

Complicating the shell But you want (and bash has) so much more: Filename metacharacters Pipes and Redirections (redirecting I/O from and to files) Command-line editing and history access Shell and environment variables Programming constructs (ifs, loops, arrays, expressions, … ) All together, a very powerful feature set, but awfully inelegant UW CSE 374 Fall 2017

Filename metacharacters - globbing Much happens to a command-line to turn it into a “call program with arguments” (or “invoke builtin”) Certain characters can expand into (potentially) multiple filenames: ~foo – home directory of user foo ~ – current user’s home directory (same as ~$user or `whoami`). * (by itself) – all files in current directory * – match 0 or more filename characters ? – match 1 filename character [abc], [a-E], [^a], . . .more matching Remember, this is done by the shell before the program sees the resulting arguments UW CSE 374 Fall 2017

Filename metacharacters: why Manually, you use them all the time to save typing. In scripts, you use them for flexibility. Example: You do not know what files will be in a directory, but you can still do: cat * (though a better script would skip directories) But what if it’s not what you want? Use quoting ("*" or '*') or escaping (\*) The rules on what needs escaping where are very arcane A way to experiment: echo echo args. . . copies its arguments to standard output after expanding metacharacters UW CSE 374 Fall 2017

History The history builtin The ! special character !!, !n, !abc, . . . Can add, substitute, etc. This is really for fast manual use; not so useful in scripts UW CSE 374 Fall 2017

Aliases Idea: Define a new command that expands to something else (not a full script) Shell builtin command: alias repeat=echo alias dir=ls alias hello="echo hello" alias rm="rm -i" % for cautious users alias % list existing aliases Often put in a file read by source or in a startup file read automatically Example: your .bashrc – feel free to change UW CSE 374 Fall 2017

Bash startup files Bash reads (sources) specific files when it starts up. Put commands here that you want to execute every time you run bash Which file gets read depends on whether bash is starting as a “login shell” or not Login shell: ~/.bash_profile (or others – see bash documentation) Non-login shell: ~/.bashrc (or others if not found) Suggestion: Include the following in your .bash_profile file so the commands in .bashrc will execute regardless of how the shell starts up if [ -f ~/.bashrc ]; then source ~/.bashrc; fi UW CSE 374 Fall 2017

Where we are Features of the bash “language”: builtins program execution filename expansion (Pocket Guide 23-25, 1st ed 22-23) history & aliases command-line editing shell and environment variables programming constructs But file editing is too useful to put off. . . so a detour to emacs (which shares some editing commands with bash) UW CSE 374 Fall 2017

What is emacs? A programmable, extensible text editor, with lots of goodies for programmers Not a full-blown IDE but much “heavier weight” than vi Top-6 commands: C-g C-x C-f C-x C-s, C-x C-w C-x C-c C-x b C-k, C-w, C-y, . . . Take the emacs tutorial to get the hang of the basics Everyone should know this at least a little – emacs editing shortcuts are common in other Linux programs Customizable with elisp (starting with your .emacs) UW CSE 374 Fall 2017

Command-line editing Lots of control-characters for moving around and editing the command-line. (Pocket Guide page 28, emacs-help, and Bash reference manual Sec. 8.4.) They make no sense in scripts Gotcha: C-s is a strange one (stops displaying output until C-q, but input does get executed) Good news: many of the control characters have the same meaning in emacs (and bash has a vi “mode” too) UW CSE 374 Fall 2017

vi(m) vs emacs You need to learn one of these Yes, there are many other editors out there, but you need to learn one of these – they are standard and available on all Unix/Linux systems (& emacs, at least, has versions for Windows, OS X) Emacs keyboard shortcuts work in many other programs and situations like bash Including vi(m) if you set the right mode! Learn them – it will make you more efficient We won’t try to dictate or settle the vi vs emacs wars You’re on your own for that! UW CSE 374 Fall 2017

Summary As promised, we are flying through this stuff! Your computing environment has files, processes, users, a shell, and programs (including emacs) Lots of small programs for files, permissions, manuals, etc. The shell has strange rules for interpreting command-lines. So far: Filename expansion History expansion The shell has lots of ways to customize/automate. So far: alias and source run (i.e., automatically source) .bash_profile or .bashrc when shell starts Next: I/O Redirection & stream details, Shell Programming UW CSE 374 Fall 2017