• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
09.using shell
 

09.using shell

on

  • 440 views

 

Statistics

Views

Total Views
440
Views on SlideShare
440
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    09.using shell 09.using shell Presentation Transcript

    • Using Shell Minsuk Lee Hansung University, Seoul, Korea minsuk@hansung.ac.krNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • What is Shell ? • As a command Interpreter – Shell interprets user command and executes program • As a programming language – Shell allows user to make script to do series of commands or procedural functions • Shell setups user configurations – Using startup script • Setting PATH, umask, any environment variableNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • Type of shells • Bourne Shell (sh) – Basic shell for UNIX system, from UNIX-v7 – Stephen Bourne created – Most of the shell is base on this Bourne shell • Korn Shell (ksh) – David Korn (AT&T) created for UNIX SVR4 – Compatible with sh, faster – Support history, alias • C Shell (csh) – Bill Joy (UCB) created for 2BSD – C language style syntax, easy to use • Bourne Again Shell (bash) – Brain Fox created in 1988 based on Bourne shell – Compatible with sh, incorporate functions from csh, ksh – Default shell for Linux • Tcsh, dtksh, zsh, …NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • How shell works ? 1. Display prompt ( $, # ) 2. Read command 3. Lookup the command 4. If it‟s internal command, execute, and goto 1 5. If it‟s external command, Fork a child process, Let it execute the command 6. Wait for child ends 7. Goto 1NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • My shell ? • Defined in /etc/passwd – Only super-user can change it • Shell is also a program – You can install ksh, csh, and use it Invoking a Bourne Shell, and exitNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • Environment Variables (1) • My working environments – Language, colors, configurations – Used by applications – „$ set‟ : current shell‟s env – „$ env‟ : global env • Can be changed – By exporting – e.g.,NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • Environment Variables (2) • Set, unset (environment) variablesNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • Using alias • Rename command Temporal unalias by „‟NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • functions • Shell allows functions with arguments – e.g., a function to make a directory and move to there $ mkcd() { mkdir -p $1 && cd $1; }NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • Command history (1) • Shell saves command history – Up/down arrow key to repeat/edit previous commands • Backs up history in ~/.bash_history file when logout • You can adjust history buffer size „$ set‟ shows all the environment variablesNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • Command history (2) • Repeat specific command (1) ! – See history by $ history or $ history | more – Try $ !<item>NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • Command history (3) • Repeat specific command (2) ! – See history by $ history or $ history | more – Try $ !<initial letter of previous command>NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • Auto complete • When type [TAB] in – Shell completes word, and/or shows choices – The word can be the name of commands, files – If you type „$ ls –l my[TAB]‟ • Shell completes „$ ls –l myfile‟, and if you type [TAB] twice, • Shell shows • After type „-‟, shell shows two file stating with “myfile-” • …NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • Bash configuration files • When login bash reads next script files in order – /etc/profile // global profile – ~/.bash_profile – ~/.bash_login // seldom used – ~/.profile // Only When .bash_profile, .bash_login does not exist – ~/.bashrc // when directed to run in above files • When logout – ~/.bash_logout • OR you can run shell script anytime by – „$ source <shell-script-file>‟ or „$ . <shell-script-file>‟NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • What you can do with scripts ? • Changing prompt – variable: PS1 `command` works ! • Changing command pathNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • Special Characters for shell char function example ; Multiple commands $ cd /tmp; ls *, ?, [ ] Wild cards (any string, one, choice) $ ls h?[a-z]* >, >>, < Redirection $ ls > ls.out | Pipe $ ls –l /etc | more ~ Home directory $ cd ~myuser - Previous working directory $ cd - „„ Ignore shell special character $ print „$SHELL‟ ““ Ignore special character except $, `, $ print “$SHELL” `` Run shell command $ print `date` Escape a shell special character $ print “$SHELL”NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • Using special CharactersNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
    • Let‟s practice • Repeat the command sequence of the screenshots • Write a shell function tc() – To replace „$ tar cvf file1.tar file1 file2 …‟ into „$ tc file1 file2 …‟ • $1 : first argument • $* : all argumentsNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA