Using Shell                        Minsuk Lee               Hansung University, Seoul, Korea                   minsuk@hans...
What is Shell ?    • As a command Interpreter         – Shell interprets user command and executes program    • As a progr...
Type of shells    • Bourne Shell (sh)         – Basic shell for UNIX system, from UNIX-v7         – Stephen Bourne created...
How shell works ?    1. Display prompt ( $, # )    2. Read command    3. Lookup the command    4. If it‟s internal command...
My shell ?    • Defined in /etc/passwd         – Only super-user can change it    • Shell is also a program         – You ...
Environment Variables (1)  • My working environments       – Language, colors, configurations       – Used by applications...
Environment Variables (2)    • Set, unset (environment) variablesNEAOSS MC2.0        CC-BY 2.0 KR, © Korea OSS Promotion F...
Using alias    • Rename command                                               Temporal unalias by „‟NEAOSS MC2.0   CC-BY 2...
functions    • Shell allows functions with arguments         – e.g., a function to make a directory and move to there     ...
Command history (1)    • Shell saves command history         – Up/down arrow key to repeat/edit previous commands    • Bac...
Command history (2)    • Repeat specific command (1) !         – See history by $ history or $ history | more         – Tr...
Command history (3)    • Repeat specific command (2) !         – See history by $ history or $ history | more         – Tr...
Auto complete    • When type [TAB] in         – Shell completes word, and/or shows choices         – The word can be the n...
Bash configuration files  • When login bash reads next script files in order       –   /etc/profile // global profile     ...
What you can do with scripts ?    • Changing prompt         – variable: PS1    `command` works !    • Changing command pat...
Special Characters for shell     char                          function                                     example       ...
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 repl...
Upcoming SlideShare
Loading in...5
×

09.using shell

325

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
325
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

09.using shell

  1. 1. Using Shell Minsuk Lee Hansung University, Seoul, Korea minsuk@hansung.ac.krNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  2. 2. 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
  3. 3. 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
  4. 4. 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
  5. 5. 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
  6. 6. 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
  7. 7. Environment Variables (2) • Set, unset (environment) variablesNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  8. 8. Using alias • Rename command Temporal unalias by „‟NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  9. 9. 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
  10. 10. 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
  11. 11. 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
  12. 12. 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
  13. 13. 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
  14. 14. 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
  15. 15. 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
  16. 16. 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
  17. 17. Using special CharactersNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  18. 18. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×