Shells, Shell Scripting, and the UNIX File System CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121.

Slides:



Advertisements
Similar presentations
Lab III – Linux at UMBC.
Advertisements

Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Chapter 9: The TC Shell Everything you thought you knew is now wrong.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
The Linux Shell The shell contains
Chapter Seven Unix Shell Environments1 System Programming UNIX Shell Environments.
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.
CS 497C – Introduction to UNIX Lecture 36: - Customizing the Environment Chin-Chih Chang
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Linux Shell. 2 Linux Command-Line Interface ■ Linux shells: A shell is a command interpreter that allows you to type commands from the keyboard to interact.
1. This presentation covers :  User Interface Administration  Files System and Services Management 2.
Nic Shulver, Scripts and Batch files Scripting in Windows and Linux What is scripting? What is it for? DOS/Windows batch files.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
Welcome to CSE  Name: Di Cao   Classroom: DL357  Class Time: T 8:30am - 9:18am  Office.
Overview of Linux CS3530 Spring 2014 Dr. José M. Garrido Department of Computer Science.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Introduction to Shell Script Programming
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
An Introduction to UNIX System --- Cosc513 Presentation n Instructor: Morteza Anvari n Author: Yonghong Pan n ID#: n Date: Jan.29, 2001.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Logging into the linux machines This series of view charts show how to log into the linux machines from the Windows environment. Machine name IP address.
1 UNIX essentials (hands-on) the directory tree running programs the shell → command line processing → special characters → command types → shell variables.
UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.
Basic Shell Scripting - Part 1 Objective - Learn to: Read Start-up Files Edit Start-up Files Modify Your User Environment Communicate with Users Write.
Workbook 6 – Part 2 The Bash Shell
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Introduction to Unix (CA263) Getting Started By Tariq Ibn Aziz.
UNIX/LINUX SHELLS.  “A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and.
Chapter 0 A “Quick-Start” into the UNIX Operating System.
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.
ITR3 lecture 6: intoduction to UNIX Thomas Krichel
June 1, 1999Customizing the UNIX Environment1 Introduction to UNIX G. Customizing the UNIX Environment.
Unix Shell Environments February 23rd, 2004 Class Meeting 6.
FTP Short for File Transfer Protocol, the protocol for exchanging files over the Internet.protocolfilesInternet works in the same way as HTTP for transferring.
UNIX shell environments CS 2204 Class meeting 6 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
User Environments Objectives –to provide appropriate environments for different types of users Contents –different login programs –user profiles –restricted.
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Introduction to Programming Using C An Introduction to Operating Systems.
Customizing the Shell Environment. UNIX Shells Two characteristics of shells –Interactive: prompts ($) and waits for your response/requests –Noninteractive:
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This.
Introduction to UNIX CS 2204 Class meeting 1 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Module 1 - Introduction to Linux. Users must log-in Linux is case sensitive File and Directories naming conventions (No spaces!) Files and Directories.
Jozef Goetz, expanded by Jozef Goetz, 2006 Credits: Parts of the slides are based on slides created by textbook authors, Syed M. Sarwar, Robert.
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Configuration your environment Many user-configurable Unix programs (such as your shell) read configuration files when they start up. These configuration.
Lesson 8-Specifying Instructions to the Shell. Overview An overview of shell. Execution of commands in a shell. Shell command-line expansion. Customizing.
Operating Systems and Using Linux Courtesy of John Y. Park 1.
Learning Unix/Linux Based on slides from: Eric Bishop.
Linux Administration Working with the BASH Shell.
Agenda Customizing a Unix/Linux account Environment Introduction to Start-up Files (.bash_profile,.bashrc,.profile,.kshrc) Safe Methods for Changing Start-up.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
A “Quick-Start” into the UNIX Operating System
SUSE Linux Enterprise Desktop Administration
Shell Features CSCI N321 – System and Network Administration
Unix Shells.
The Linux Operating System
Shell Environments.
UNIX and Shell Programming (06CS36)
An Introduction to UNIX System --- Cosc513 Presentation
Unix : Introduction and Commands
Shells, Help, and Paths.
Linux Shell Script Programming
Logging into the linux machines
Unix Shell Environments
Chapter 3 The UNIX Shells
CMPSC 60: Week 5 Discussion
Presentation transcript:

Shells, Shell Scripting, and the UNIX File System CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.

Shell Overview What is a Shell? UNIX shells provide a "command line" interface which allows the user to enter commands which are translated by the shell into something the kernel can comprehend and then is sent off to the kernel for it to act upon. UNIX shells provide a "command line" interface which allows the user to enter commands which are translated by the shell into something the kernel can comprehend and then is sent off to the kernel for it to act upon. The user can pick their shell (just like the applications, desktop manger, window manager, etc. on a UNIX system). The user can pick their shell (just like the applications, desktop manger, window manager, etc. on a UNIX system). UMBC Shells On the UMBC GL network, the default UNIX shell is tcsh - Turbo C SHell. The default can be changed by the user via On the UMBC GL network, the default UNIX shell is tcsh - Turbo C SHell. The default can be changed by the user via Shells available on GL include: Shells available on GL include: tcsh - Turbo C SHell tcsh - Turbo C SHell csh - C SHell csh - C SHell ksh - Korn SHell ksh - Korn SHell bash - Bourne Again SHell bash - Bourne Again SHell sh - SHell sh - SHell

Shell Overview Linux Default Shell Linux Default Shell Most Linux systems (especially home installations) default to the bash shell. Most Linux systems (especially home installations) default to the bash shell. Changing Your Shell - On a Home Based System Changing Your Shell - On a Home Based System Usually there is a command called chsh that stands for change shell. You have to enter your password and then the absolute path to the new shell that you wish to use. Usually there is a command called chsh that stands for change shell. You have to enter your password and then the absolute path to the new shell that you wish to use. (06:08 PM): chsh Changing shell for Eric. Password: New shell [/bin/bash]: /bin/csh Shell changed.

Aliasing Commands A helpful feature, especially for many users new to UNIX, is the alias function. A helpful feature, especially for many users new to UNIX, is the alias function. The alias command assigns a command, possibly with many options and flags, to another name. Usually it is a shorter name or one that is easier to remember. The alias command assigns a command, possibly with many options and flags, to another name. Usually it is a shorter name or one that is easier to remember. Setting up an alias: The exact syntax depends on the shell that you are using. We will cover how to do it under tcsh and bash. Most other shells use a similar or identical syntax. The exact syntax depends on the shell that you are using. We will cover how to do it under tcsh and bash. Most other shells use a similar or identical syntax. tcsh syntax: tcsh syntax: alias alias bash syntax: bash syntax: alias = alias =

Environment Variables Think of the shell as any other program that you write. Your program maintains information about its current state. Since the shell's main job is to act as a liaison between the kernel and the user, it maintains information about the computing environment. The environment variables hold this information. Think of the shell as any other program that you write. Your program maintains information about its current state. Since the shell's main job is to act as a liaison between the kernel and the user, it maintains information about the computing environment. The environment variables hold this information.

Viewing Your Environment Variables Most UNIX systems provide a command env that will allow you to see all of these variables that the shell is maintaining. Most UNIX systems provide a command env that will allow you to see all of these variables that the shell is maintaining. Here is an example of the env command issued on one of the linix.gl servers using the tcsh shell: Here is an example of the env command issued on one of the linix.gl servers using the tcsh shell:HOME=/afs/umbc.edu/users/j/o/josey1/homeUSER=josey1LOGNAME=josey1 PATH=.:/afs/umbc.edu/users/j/o/josey1/home/bin:/usr/local/bin:/usr/bsd:/bin :/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/X11:/etc:/usr/etc:/usr/k5/bi n:/usr/afsws/bin:/bin:/usr/java/bin:/usr/afsws/bin:/usr/X11R6/bin MAIL=/afs/umbc.edu/users/j/o/josey1/Mail/inboxSHELL=/bin/tcshTERM=xtermDISPLAY=linux2.gl.umbc.edu:10.0KRB5CCNAME=FILE:/tmp/krb5cc_l29893HOSTTYPE=i386-linuxVENDOR=intelOSTYPE=linuxMACHTYPE=i386SHLVL=1PWD=/afs/umbc.edu/users/j/o/josey1/homeGROUP=generalHOST=linux2.gl.umbc.eduHOSTNAME=linux2.gl.umbc.edu LESSOPEN=|/usr/bin/lesspipe.sh %s TZ=EST5EDTMANPATH=/usr/X11R6/man:/usr/k5/man:/usr/local/man:/usr/man:/usr/share/manEDITOR=/usr/local/bin/pico

Important Environment Variables HOME - your home directory. HOME - your home directory. USER and LOGNAME - your login ID. USER and LOGNAME - your login ID. HOSTNAME - the name of the host computer. HOSTNAME - the name of the host computer. PWD - the current working directory. PWD - the current working directory. MAIL - where your mail is located. MAIL - where your mail is located. PATH - a list of directories in which to look for executable commands. PATH - a list of directories in which to look for executable commands. Certain applications and commands may communicate with the shell and reference the environment variables that it maintains. Certain applications and commands may communicate with the shell and reference the environment variables that it maintains. For example, it seems that frm and nfrm seem not to work if $MAIL is not defined. frm and nfrm are commands to list the contents of your inbox without logging into pine. For example, it seems that frm and nfrm seem not to work if $MAIL is not defined. frm and nfrm are commands to list the contents of your inbox without logging into pine.

~/bin bin directories bin directories Program files or commands, also called binary executable files and script files, are kept in various places throughout the system. Program files or commands, also called binary executable files and script files, are kept in various places throughout the system. Usually these binary files are stored in bin (short for binary) directories throughout the system. Usually these binary files are stored in bin (short for binary) directories throughout the system. If you take a look at the paths are stored in your $PATH environment variable, you will notice that many of these directories end in.../bin. If you take a look at the paths are stored in your $PATH environment variable, you will notice that many of these directories end in.../bin. Your ~/bin directory: Your ~/bin directory: You may also notice that your path may contain a bin directory that is listed as being in your home directory (/afs/umbc.edu/users/u/s/username/home/bin). You may also notice that your path may contain a bin directory that is listed as being in your home directory (/afs/umbc.edu/users/u/s/username/home/bin). This is where you can store your own compiled programs or scripts that you would like to be able to run from anywhere on the system. This is where you can store your own compiled programs or scripts that you would like to be able to run from anywhere on the system.

Introducing tcsh Currently, the default shell on UMBC’s GL system is tcsh. Currently, the default shell on UMBC’s GL system is tcsh. tcsh is short for Turbo C SHell. tcsh is short for Turbo C SHell. Customizing your tcsh shell Customizing your tcsh shell The guide linked from the course webpage has a pretty good section on customizing your tcsh shell. The guide linked from the course webpage has a pretty good section on customizing your tcsh shell. The URL of that specific section is The URL of that specific section is The.cshrc file. The.cshrc file. tcsh looks for a configuration file at startup time called "~/.cshrc" tcsh looks for a configuration file at startup time called "~/.cshrc" I recommend backing up a copy of your account configuration files before modifying them (such as "cp.cshrc.cshrc.bak"). I recommend backing up a copy of your account configuration files before modifying them (such as "cp.cshrc.cshrc.bak"). Changes to your configuration file do not effect the system immediately after you save the file. Changes to your configuration file do not effect the system immediately after you save the file. You might just be able to issue the command source ~/.cshrc to make the changes take effect. You might just be able to issue the command source ~/.cshrc to make the changes take effect. You may need to logout and log back in for these changes to take effect. You may need to logout and log back in for these changes to take effect.

# This is the default standard #.cshrc provided to csh users. # They are expected to edit it to # meet their own needs. ###Path is loaded with user's bin(s) if ( -o /bin/su ) then unset path unset pathelse set path = (. $HOME/bin) set path = (. $HOME/bin)endif ##### Load up the path with some ##### additional directories. set path=( $path /usr/local/bin /usr/bsd /bin /usr/bin \ /usr/sbin /usr/bin/X11 /usr/local/X11 \ /etc /usr/etc ) ##### load machine-specific settings if ( -r /usr/site/etc/system.cshrc ) then source /usr/site/etc/system.cshrc source /usr/site/etc/system.cshrcendif if ($?prompt) then ##### sets the prompt if ( -o /bin/su ) then set prompt = "umbc8[1]% “ else set prompt = "`hostname -s` [\!]# “ endif ##### some environment variables stty intr "^C" kill "^U" echoe setenv EDITOR /usr/local/bin/pico umask 077 set history = 100 set filec ##### aliases alias h history alias help apropos alias rm "rm -i“ alias ls 'ls -C --color‘ alias mailtest.mailtest ##### my additions here down alias mem "quota -v“ endif

tcsh Customization Tricks Since many students do not ever look at the core dump files, they are simply an annoyance that takes up space in your account. To prevent core dumps from being created, add the following line to your.cshrc file: Since many students do not ever look at the core dump files, they are simply an annoyance that takes up space in your account. To prevent core dumps from being created, add the following line to your.cshrc file: limit coredumpsize 0 For a better version of auto completion, add the following line to your.cshrc file: For a better version of auto completion, add the following line to your.cshrc file: set autolist

Login and Logout Files When using the tcsh shell, it attempts to execute certain files when you log onto the system and when you logout of the system. When using the tcsh shell, it attempts to execute certain files when you log onto the system and when you logout of the system. When you logon, tcsh looks for a file called ".login" and tries to execute the contents of the file. When you logon, tcsh looks for a file called ".login" and tries to execute the contents of the file. When you logout, tcsh looks for a file called ".logout" and tries to execute the contents of the file When you logout, tcsh looks for a file called ".logout" and tries to execute the contents of the file

Example.login File # This is the default standard.login provided to csh users. # They are expected to edit it to meet their own needs. # Set the interrupt character to Ctrl-c and do clean backspacing. ##### sets interrupt sequence ##### if (-t 0) then stty intr '^C' echoe endif ##### Set the TERM environment variable ##### eval `tset -s -Q` ####### my modifications from here ####### # print new mail echo "--- New Mail Messages ---“ nfrm # print my quota echo "\n--- My Disk Quota ---“ quota –v echo "“ # remove that annoying netscape lock rm -f.netscape/lock

Example.logout File # File:.logout # clean up Internet Explorer’s cache rm -rf "/afs/umbc.edu/users/u/s/username/ho me/.2kprofile/Temporary Internet Files“ # clean up UNIX Netscape's cache rm -rf.netscape/cache # clear the screen clear

Introduction to bash The bash shell is one of the many shells that are available to you on the GL network. The bash shell is one of the many shells that are available to you on the GL network. Almost any home installation of Linux defaults to the bash shell. Almost any home installation of Linux defaults to the bash shell. bash is one the many GNU.org ( projects. bash is one the many GNU.org ( projects. bash manuals: bash manuals: A comprehensive online manual is provided at A comprehensive online manual is provided at Aliases a/html_chapter/bashref_6.html#SEC77 Aliases a/html_chapter/bashref_6.html#SEC77http:// 2.05a/html_chapter/bashref_6.html#SEC77http:// 2.05a/html_chapter/bashref_6.html#SEC77 Controlling the Prompt a/html_chapter/bashref_6.html#SEC81 Controlling the Prompt a/html_chapter/bashref_6.html#SEC81http:// 2.05a/html_chapter/bashref_6.html#SEC81http:// 2.05a/html_chapter/bashref_6.html#SEC81

bash Configuration Files bash has two different login files. bash has two different login files..bashrc gets read when you open a local shell on a machine.bashrc gets read when you open a local shell on a machine.bash_profile only gets read if and only if you login from a remote machine. Note that.bash_profile itself reads in your.bashrc file as well..bash_profile only gets read if and only if you login from a remote machine. Note that.bash_profile itself reads in your.bashrc file as well. If you want aliases to be executed regardless, then you should put them in the.bashrc file. If you want aliases to be executed regardless, then you should put them in the.bashrc file. There are no default bash configuration files currently being provided for GL. The two example configuration files are courtesy of Dan Hood. There are no default bash configuration files currently being provided for GL. The two example configuration files are courtesy of Dan Hood.

# File:.bashrc # # Description: A default #.bashrc for GL ###Source global defs ### if [ -f /etc/bashrc ]; then. /etc/bashrc fi ###set the prompt ### # uncomment out only one # this is hostname and time " # this is hostname and # history number #PS1="\h-(\!)# " # this is hostname and # working directory #PS1="\h-(\w)# " # this is hostname and # shortened working # directory #PS1="\h-(\W)# " ### path manipulation ### # add ~/bin to the path, # cwd as well PATH="$PATH:$HOME/bin:./“ ### env variables ### # make sure that you # change this to your # username MAIL="/afs/umbc.edu/users/u/ s/username/Mail/inbox“ export PATH unset USERNAME ### User-specific aliases ### and functions ### alias rm="rm -i"

# File:.bash_profile # Get the aliases and functions # Get whatever is in your #.bashrc config file if [ -f ~/.bashrc ]; then. ~/.bashrc fi

UNIX File System Overview Covered in class! Covered in class!