shell features csci n321 – system and network administration copyright © 2000, 2005 by scott orr...
TRANSCRIPT
![Page 1: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/1.jpg)
Shell Features
CSCI N321 – System and Network Administration
Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University
![Page 2: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/2.jpg)
Section Overview
I/O Substitution
Pathname Substitution
Parameter/Variable Substitution
Command Substitution
![Page 3: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/3.jpg)
References
CQU 85321 System Administration Course
TextbookChapter 7
Lectures2002 #6
![Page 4: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/4.jpg)
UNIX Shell
Enables users to enter commandsText basedSimilar to MSDOS Command Prompt (but are much more powerful)Common Shells Bourne: sh, ksh, bash C: csh, tcsh
![Page 5: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/5.jpg)
Shell Features
Environment variables and aliasesHistory of commands usedProgramming constructsAdded features in newer shells Command line editing Command line completion
Shell configuration files
![Page 6: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/6.jpg)
Command History/Editing
Most shells maintain a history of previously entered commandshistory: View list of commands!#: Rerun command number #Command line editing Up/down arrow keys to cycle through list Left/right arrow keys to move within listed
command <ctrl><a>: move to start of command line <ctrl><e>: move to end of command line
![Page 7: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/7.jpg)
Command Aliases
Shortcut for command lineSet/view using the alias commandExamples: alias ls='ls --color=tty' alias rm='rm –i'
![Page 8: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/8.jpg)
Shell Variables
Customize environmentShared settings for programsAssigning Variables: var=“value”Referencing Variables: $varViewing variables: set, printenvVariables are case sensitive
![Page 9: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/9.jpg)
Special Shell Variables
HOME – User’s home directory pathSHELL – Current shellUID – User’s UID numberPATH – Program search pathPS1/PS2 – Format for command prompt (prompt for csh/tcsh)
Must use “export” to set variables in shell
![Page 10: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/10.jpg)
bash Shell Logins
/bin/bash/bin/bash
/etc/profile/etc/profile /etc/profile.d//etc/profile.d//etc/bashrc/etc/bashrc
~/.bash_profile~/.bash_profile ~/.bashrc~/.bashrc
~/.bash_login~/.bash_login
or
or~/.profile~/.profile
![Page 11: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/11.jpg)
Parsing the Command Line
Breaks the command line into componentsSpecial Characters modify operation How command runs Filename Expansion I/O redirection Quotes
![Page 12: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/12.jpg)
Command Run Modifiers
Write Space – Separate argumentsNewline (<cr>) – End of lineSpecial Characters
CharacterCharacter MeaningMeaning
; Separate multiple command on same line
& Run command in the background
\ At end of line, continue on next line
|| && Logical operators based on exit status
![Page 13: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/13.jpg)
Filename Expansion
Special characters representing multiple filenamesAlso referred to as globbing
CharacterCharacter MatchesMatches
* 0 or more characters
? 1 character
[ ] Matches any 1 character in [ ](including ranges)
[^ ] Matches any 1 character not in [ ](including ranges)
![Page 14: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/14.jpg)
I/O Redirection
Modifies how input and output is usedChain command to solve bigger tasks
CharactersCharacters ResultResult
command < file Use file as input for command
command > file Store command output in file
command >> file Append command output to file
command << label
Input from standard input until label
`command` Execute command then replace command name with its output
cmd1 | cmd2 Use output from cmd1 as input to cmd2
![Page 15: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/15.jpg)
Standard File Descriptors
Special file pointers for input and outputExtension from C language
NameName DescriptDescriptoror
Default Default DeviceDevice
Standard input (stdin) 0 Keyboard
Standard output (stdout)
1 Screen
Standard error (stderr)
2 Screen
![Page 16: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/16.jpg)
Using File Descriptors
Finer control over input/output redirectionstdout and stderr can be redirected to same file
CharactersCharacters ResultResult
command 2> file stderr output stored in file
cmd >& <file-descriptor>
Output redirected to <file-descriptor>
Cmd > file 2>&1 Stderr & stdout redirected to file
![Page 17: Shell Features CSCI N321 – System and Network Administration Copyright © 2000, 2005 by Scott Orr and the Trustees of Indiana University](https://reader036.vdocument.in/reader036/viewer/2022062408/56649e725503460f94b71f34/html5/thumbnails/17.jpg)
Quote Characters
Prevent special characters from being interpreted by the shell
CharacteCharacterr
NameName ActionAction
‘ Single Quote Shell ignores all special characters enclosed ‘ ’
“ Double Quote Shell ignores all special characters enclosed “ ”except for $ ‘ \
\ Backslash Shell ignores character immediately following \