SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Using Shell

                        Minsuk Lee
               Hansung University, Seoul, Korea
                   minsuk@hansung.ac.kr



NEAOSS 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 variable




NEAOSS 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 1

NEAOSS 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 exit




NEAOSS 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) variables




NEAOSS 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 variables



NEAOSS 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 path




NEAOSS 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 Characters




NEAOSS 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 arguments




NEAOSS MC2.0            CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA

Weitere ähnliche Inhalte

Was ist angesagt?

Functional Hostnames and Why they are Bad
Functional Hostnames and Why they are BadFunctional Hostnames and Why they are Bad
Functional Hostnames and Why they are BadPuppet
 
Apache HBase - Lab Assignment
Apache HBase - Lab AssignmentApache HBase - Lab Assignment
Apache HBase - Lab AssignmentFarzad Nozarian
 
Linux day 2.ppt
Linux day  2.pptLinux day  2.ppt
Linux day 2.pptKalkey
 
Chef or how to make computers do the work for us
Chef or how to make computers do the work for usChef or how to make computers do the work for us
Chef or how to make computers do the work for ussickill
 
SWORD & ResourceSync - Stuart Lewis
SWORD & ResourceSync - Stuart Lewis SWORD & ResourceSync - Stuart Lewis
SWORD & ResourceSync - Stuart Lewis Repository Fringe
 
Linux system administration
Linux system administrationLinux system administration
Linux system administrationorionsconsulting
 
Bacula Overview
Bacula OverviewBacula Overview
Bacula Overviewsambismo
 
Introduction to linux
Introduction to linuxIntroduction to linux
Introduction to linuxGourav Varma
 
Implementing Hadoop on a single cluster
Implementing Hadoop on a single clusterImplementing Hadoop on a single cluster
Implementing Hadoop on a single clusterSalil Navgire
 
20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasag20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasaggarrett honeycutt
 
Operating Systems 1
Operating Systems 1Operating Systems 1
Operating Systems 1hutchison
 
Terminal basic-commands(Unix) -partI
Terminal basic-commands(Unix) -partITerminal basic-commands(Unix) -partI
Terminal basic-commands(Unix) -partIKedar Bhandari
 

Was ist angesagt? (20)

Functional Hostnames and Why they are Bad
Functional Hostnames and Why they are BadFunctional Hostnames and Why they are Bad
Functional Hostnames and Why they are Bad
 
Apache HBase - Lab Assignment
Apache HBase - Lab AssignmentApache HBase - Lab Assignment
Apache HBase - Lab Assignment
 
Linux day 2.ppt
Linux day  2.pptLinux day  2.ppt
Linux day 2.ppt
 
07.using vi
07.using vi07.using vi
07.using vi
 
Chef or how to make computers do the work for us
Chef or how to make computers do the work for usChef or how to make computers do the work for us
Chef or how to make computers do the work for us
 
SWORD & ResourceSync - Stuart Lewis
SWORD & ResourceSync - Stuart Lewis SWORD & ResourceSync - Stuart Lewis
SWORD & ResourceSync - Stuart Lewis
 
Suman bhatt
Suman bhattSuman bhatt
Suman bhatt
 
Linux system administration
Linux system administrationLinux system administration
Linux system administration
 
Advanced CouchDB
Advanced CouchDBAdvanced CouchDB
Advanced CouchDB
 
Dockerの準備
Dockerの準備Dockerの準備
Dockerの準備
 
Bacula Overview
Bacula OverviewBacula Overview
Bacula Overview
 
Introduction to linux
Introduction to linuxIntroduction to linux
Introduction to linux
 
Implementing Hadoop on a single cluster
Implementing Hadoop on a single clusterImplementing Hadoop on a single cluster
Implementing Hadoop on a single cluster
 
20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasag20090514 Introducing Puppet To Sasag
20090514 Introducing Puppet To Sasag
 
2 db2 instance creation
2 db2 instance creation2 db2 instance creation
2 db2 instance creation
 
Operating Systems 1
Operating Systems 1Operating Systems 1
Operating Systems 1
 
Terminal basic-commands(Unix) -partI
Terminal basic-commands(Unix) -partITerminal basic-commands(Unix) -partI
Terminal basic-commands(Unix) -partI
 
6. centos networking
6. centos networking6. centos networking
6. centos networking
 
Dcp'14 drush
Dcp'14 drushDcp'14 drush
Dcp'14 drush
 
005 skyeye
005 skyeye005 skyeye
005 skyeye
 

Andere mochten auch

The linux command line for total beginners
The linux command line  for total beginnersThe linux command line  for total beginners
The linux command line for total beginnersCorrie Watt
 
The Complete Roadmap Workbook Final Use
The Complete Roadmap Workbook Final UseThe Complete Roadmap Workbook Final Use
The Complete Roadmap Workbook Final Usepaulageorge
 
Data and Sorting Algoritm
Data and Sorting AlgoritmData and Sorting Algoritm
Data and Sorting AlgoritmMinsuk Lee
 
Small business and enterprenure
Small business and enterprenureSmall business and enterprenure
Small business and enterprenurerounaq
 
Future of sharing beyond
Future of sharing   beyondFuture of sharing   beyond
Future of sharing beyondNick Rappolt
 
2011 National Space Symposium
2011 National Space Symposium 2011 National Space Symposium
2011 National Space Symposium SpaceFoundation
 
Portfolio Presentation 2
Portfolio Presentation 2Portfolio Presentation 2
Portfolio Presentation 2rutheast
 
岸角客家文化
岸角客家文化岸角客家文化
岸角客家文化Minghua Lin
 
과학의날-강연-양정중학교
과학의날-강연-양정중학교과학의날-강연-양정중학교
과학의날-강연-양정중학교Minsuk Lee
 
왜 소프트웨어를 배워야할까?
왜 소프트웨어를 배워야할까?왜 소프트웨어를 배워야할까?
왜 소프트웨어를 배워야할까?Minsuk Lee
 
983896 634395133169998750
983896 634395133169998750983896 634395133169998750
983896 634395133169998750KIET
 
Pumping Corn Into Wisconsin: Consideration for Ethanol Legislation
Pumping Corn Into Wisconsin: Consideration for Ethanol LegislationPumping Corn Into Wisconsin: Consideration for Ethanol Legislation
Pumping Corn Into Wisconsin: Consideration for Ethanol LegislationJustin Dohms
 
Modelo envejecimiento normal
Modelo envejecimiento normalModelo envejecimiento normal
Modelo envejecimiento normalBrain Dynamics
 
これからの司法書士に求められるIT力強化セミナー
これからの司法書士に求められるIT力強化セミナーこれからの司法書士に求められるIT力強化セミナー
これからの司法書士に求められるIT力強化セミナーYukidama
 
綠色奇蹟—溪州馬拉巴栗
綠色奇蹟—溪州馬拉巴栗綠色奇蹟—溪州馬拉巴栗
綠色奇蹟—溪州馬拉巴栗Minghua Lin
 
3phase induction motor
3phase induction motor3phase induction motor
3phase induction motorNaveen Sihag
 

Andere mochten auch (20)

The linux command line for total beginners
The linux command line  for total beginnersThe linux command line  for total beginners
The linux command line for total beginners
 
Binary search
Binary searchBinary search
Binary search
 
The Complete Roadmap Workbook Final Use
The Complete Roadmap Workbook Final UseThe Complete Roadmap Workbook Final Use
The Complete Roadmap Workbook Final Use
 
Data and Sorting Algoritm
Data and Sorting AlgoritmData and Sorting Algoritm
Data and Sorting Algoritm
 
Small business and enterprenure
Small business and enterprenureSmall business and enterprenure
Small business and enterprenure
 
Future of sharing beyond
Future of sharing   beyondFuture of sharing   beyond
Future of sharing beyond
 
2011 National Space Symposium
2011 National Space Symposium 2011 National Space Symposium
2011 National Space Symposium
 
Portfolio Presentation 2
Portfolio Presentation 2Portfolio Presentation 2
Portfolio Presentation 2
 
Aart1400 seminar
Aart1400 seminarAart1400 seminar
Aart1400 seminar
 
岸角客家文化
岸角客家文化岸角客家文化
岸角客家文化
 
Pp R L S 2011
Pp  R L S  2011Pp  R L S  2011
Pp R L S 2011
 
과학의날-강연-양정중학교
과학의날-강연-양정중학교과학의날-강연-양정중학교
과학의날-강연-양정중학교
 
왜 소프트웨어를 배워야할까?
왜 소프트웨어를 배워야할까?왜 소프트웨어를 배워야할까?
왜 소프트웨어를 배워야할까?
 
983896 634395133169998750
983896 634395133169998750983896 634395133169998750
983896 634395133169998750
 
Pumping Corn Into Wisconsin: Consideration for Ethanol Legislation
Pumping Corn Into Wisconsin: Consideration for Ethanol LegislationPumping Corn Into Wisconsin: Consideration for Ethanol Legislation
Pumping Corn Into Wisconsin: Consideration for Ethanol Legislation
 
Modelo envejecimiento normal
Modelo envejecimiento normalModelo envejecimiento normal
Modelo envejecimiento normal
 
pengertian filsafat
pengertian filsafatpengertian filsafat
pengertian filsafat
 
これからの司法書士に求められるIT力強化セミナー
これからの司法書士に求められるIT力強化セミナーこれからの司法書士に求められるIT力強化セミナー
これからの司法書士に求められるIT力強化セミナー
 
綠色奇蹟—溪州馬拉巴栗
綠色奇蹟—溪州馬拉巴栗綠色奇蹟—溪州馬拉巴栗
綠色奇蹟—溪州馬拉巴栗
 
3phase induction motor
3phase induction motor3phase induction motor
3phase induction motor
 

Ähnlich wie 09.using shell

05.linux basic-operations-1
05.linux basic-operations-105.linux basic-operations-1
05.linux basic-operations-1Minsuk Lee
 
Course 102: Lecture 10: Learning About the Shell
Course 102: Lecture 10: Learning About the Shell Course 102: Lecture 10: Learning About the Shell
Course 102: Lecture 10: Learning About the Shell Ahmed El-Arabawy
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell ScriptingMustafa Qasim
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboyKenneth Geisshirt
 
(Ebook) linux shell scripting tutorial
(Ebook) linux shell scripting tutorial(Ebook) linux shell scripting tutorial
(Ebook) linux shell scripting tutorialjayaramprabhu
 
Shell Scripting crash course.pdf
Shell Scripting crash course.pdfShell Scripting crash course.pdf
Shell Scripting crash course.pdfharikrishnapolaki
 
04 using and_configuring_bash
04 using and_configuring_bash04 using and_configuring_bash
04 using and_configuring_bashShay Cohen
 
Redirection of output and input in unix/linux
Redirection of output and input in unix/linuxRedirection of output and input in unix/linux
Redirection of output and input in unix/linuxPanu Ausavasereelert
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboyKenneth Geisshirt
 
Operating system (remuel)
Operating system (remuel)Operating system (remuel)
Operating system (remuel)Remuel Malinao
 
Bash shell
Bash shellBash shell
Bash shellxylas121
 
Presentation for RHCE in linux
Presentation  for  RHCE in linux Presentation  for  RHCE in linux
Presentation for RHCE in linux Kuldeep Tiwari
 
Airlover 20030324 1
Airlover 20030324 1Airlover 20030324 1
Airlover 20030324 1Dr.Ravi
 
Shell_Scripting.ppt
Shell_Scripting.pptShell_Scripting.ppt
Shell_Scripting.pptKiranMantri
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in LinuxAnu Chaudhry
 
InSpec Workshop DevSecCon 2017
InSpec Workshop DevSecCon 2017InSpec Workshop DevSecCon 2017
InSpec Workshop DevSecCon 2017Mandi Walls
 

Ähnlich wie 09.using shell (20)

05.linux basic-operations-1
05.linux basic-operations-105.linux basic-operations-1
05.linux basic-operations-1
 
Course 102: Lecture 10: Learning About the Shell
Course 102: Lecture 10: Learning About the Shell Course 102: Lecture 10: Learning About the Shell
Course 102: Lecture 10: Learning About the Shell
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell Scripting
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
21bUc8YeDzZpE
21bUc8YeDzZpE21bUc8YeDzZpE
21bUc8YeDzZpE
 
21bUc8YeDzZpE
21bUc8YeDzZpE21bUc8YeDzZpE
21bUc8YeDzZpE
 
21bUc8YeDzZpE
21bUc8YeDzZpE21bUc8YeDzZpE
21bUc8YeDzZpE
 
(Ebook) linux shell scripting tutorial
(Ebook) linux shell scripting tutorial(Ebook) linux shell scripting tutorial
(Ebook) linux shell scripting tutorial
 
Shell Scripting crash course.pdf
Shell Scripting crash course.pdfShell Scripting crash course.pdf
Shell Scripting crash course.pdf
 
04 using and_configuring_bash
04 using and_configuring_bash04 using and_configuring_bash
04 using and_configuring_bash
 
Redirection of output and input in unix/linux
Redirection of output and input in unix/linuxRedirection of output and input in unix/linux
Redirection of output and input in unix/linux
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
UnixShells.ppt
UnixShells.pptUnixShells.ppt
UnixShells.ppt
 
Operating system (remuel)
Operating system (remuel)Operating system (remuel)
Operating system (remuel)
 
Bash shell
Bash shellBash shell
Bash shell
 
Presentation for RHCE in linux
Presentation  for  RHCE in linux Presentation  for  RHCE in linux
Presentation for RHCE in linux
 
Airlover 20030324 1
Airlover 20030324 1Airlover 20030324 1
Airlover 20030324 1
 
Shell_Scripting.ppt
Shell_Scripting.pptShell_Scripting.ppt
Shell_Scripting.ppt
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in Linux
 
InSpec Workshop DevSecCon 2017
InSpec Workshop DevSecCon 2017InSpec Workshop DevSecCon 2017
InSpec Workshop DevSecCon 2017
 

Mehr von Minsuk Lee

CES 처음 가는 분을 위한 가이드
CES 처음 가는 분을 위한 가이드CES 처음 가는 분을 위한 가이드
CES 처음 가는 분을 위한 가이드Minsuk Lee
 
NIA-PaaS-TA Pub 키노트
NIA-PaaS-TA Pub 키노트NIA-PaaS-TA Pub 키노트
NIA-PaaS-TA Pub 키노트Minsuk Lee
 
모두콘, 어떻게 배울 것인가 발제.
모두콘,  어떻게 배울 것인가 발제.모두콘,  어떻게 배울 것인가 발제.
모두콘, 어떻게 배울 것인가 발제.Minsuk Lee
 
GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자
GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자
GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자Minsuk Lee
 
개발자, 회사.. 왜 오픈소스를 해야할까?
개발자, 회사.. 왜 오픈소스를 해야할까?개발자, 회사.. 왜 오픈소스를 해야할까?
개발자, 회사.. 왜 오픈소스를 해야할까?Minsuk Lee
 
진정한 소프트웨어 융합교육에 대하여
진정한 소프트웨어 융합교육에 대하여 진정한 소프트웨어 융합교육에 대하여
진정한 소프트웨어 융합교육에 대하여 Minsuk Lee
 
FOSS CON Korea 2018
FOSS CON Korea 2018FOSS CON Korea 2018
FOSS CON Korea 2018Minsuk Lee
 
소프트웨어 공부하는법
소프트웨어 공부하는법소프트웨어 공부하는법
소프트웨어 공부하는법Minsuk Lee
 
자기소개서, 이력서 쓰는 법
자기소개서, 이력서 쓰는 법자기소개서, 이력서 쓰는 법
자기소개서, 이력서 쓰는 법Minsuk Lee
 
왜 우리는 개발자에 집중하지 않는가?
왜 우리는 개발자에 집중하지 않는가?왜 우리는 개발자에 집중하지 않는가?
왜 우리는 개발자에 집중하지 않는가?Minsuk Lee
 
Somul 2017-이민석
Somul 2017-이민석Somul 2017-이민석
Somul 2017-이민석Minsuk Lee
 
국민대-컴퓨터프로그래밍-2017-1-오프라인강좌
국민대-컴퓨터프로그래밍-2017-1-오프라인강좌국민대-컴퓨터프로그래밍-2017-1-오프라인강좌
국민대-컴퓨터프로그래밍-2017-1-오프라인강좌Minsuk Lee
 
소프트웨어, 정말 되는 건가?
소프트웨어, 정말 되는 건가?소프트웨어, 정말 되는 건가?
소프트웨어, 정말 되는 건가?Minsuk Lee
 
소프트웨어, 소프트웨어 개발자
소프트웨어, 소프트웨어 개발자소프트웨어, 소프트웨어 개발자
소프트웨어, 소프트웨어 개발자Minsuk Lee
 
프로그램 기초
프로그램 기초프로그램 기초
프로그램 기초Minsuk Lee
 
Software Company, Open Soure Software Company
Software Company, Open Soure Software CompanySoftware Company, Open Soure Software Company
Software Company, Open Soure Software CompanyMinsuk Lee
 
Open Source 그리고 git과 github, code review
Open Source 그리고 git과 github, code reviewOpen Source 그리고 git과 github, code review
Open Source 그리고 git과 github, code reviewMinsuk Lee
 
국민대학교 컴퓨터프로그래밍
국민대학교 컴퓨터프로그래밍국민대학교 컴퓨터프로그래밍
국민대학교 컴퓨터프로그래밍Minsuk Lee
 
it's software!
it's software!it's software!
it's software!Minsuk Lee
 
Deview-2014-자신있는개발자에서 훌륭한개발자로
Deview-2014-자신있는개발자에서 훌륭한개발자로Deview-2014-자신있는개발자에서 훌륭한개발자로
Deview-2014-자신있는개발자에서 훌륭한개발자로Minsuk Lee
 

Mehr von Minsuk Lee (20)

CES 처음 가는 분을 위한 가이드
CES 처음 가는 분을 위한 가이드CES 처음 가는 분을 위한 가이드
CES 처음 가는 분을 위한 가이드
 
NIA-PaaS-TA Pub 키노트
NIA-PaaS-TA Pub 키노트NIA-PaaS-TA Pub 키노트
NIA-PaaS-TA Pub 키노트
 
모두콘, 어떻게 배울 것인가 발제.
모두콘,  어떻게 배울 것인가 발제.모두콘,  어떻게 배울 것인가 발제.
모두콘, 어떻게 배울 것인가 발제.
 
GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자
GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자
GDG-DevFest, 만들면서 자랑하면서 성장하는 개발자
 
개발자, 회사.. 왜 오픈소스를 해야할까?
개발자, 회사.. 왜 오픈소스를 해야할까?개발자, 회사.. 왜 오픈소스를 해야할까?
개발자, 회사.. 왜 오픈소스를 해야할까?
 
진정한 소프트웨어 융합교육에 대하여
진정한 소프트웨어 융합교육에 대하여 진정한 소프트웨어 융합교육에 대하여
진정한 소프트웨어 융합교육에 대하여
 
FOSS CON Korea 2018
FOSS CON Korea 2018FOSS CON Korea 2018
FOSS CON Korea 2018
 
소프트웨어 공부하는법
소프트웨어 공부하는법소프트웨어 공부하는법
소프트웨어 공부하는법
 
자기소개서, 이력서 쓰는 법
자기소개서, 이력서 쓰는 법자기소개서, 이력서 쓰는 법
자기소개서, 이력서 쓰는 법
 
왜 우리는 개발자에 집중하지 않는가?
왜 우리는 개발자에 집중하지 않는가?왜 우리는 개발자에 집중하지 않는가?
왜 우리는 개발자에 집중하지 않는가?
 
Somul 2017-이민석
Somul 2017-이민석Somul 2017-이민석
Somul 2017-이민석
 
국민대-컴퓨터프로그래밍-2017-1-오프라인강좌
국민대-컴퓨터프로그래밍-2017-1-오프라인강좌국민대-컴퓨터프로그래밍-2017-1-오프라인강좌
국민대-컴퓨터프로그래밍-2017-1-오프라인강좌
 
소프트웨어, 정말 되는 건가?
소프트웨어, 정말 되는 건가?소프트웨어, 정말 되는 건가?
소프트웨어, 정말 되는 건가?
 
소프트웨어, 소프트웨어 개발자
소프트웨어, 소프트웨어 개발자소프트웨어, 소프트웨어 개발자
소프트웨어, 소프트웨어 개발자
 
프로그램 기초
프로그램 기초프로그램 기초
프로그램 기초
 
Software Company, Open Soure Software Company
Software Company, Open Soure Software CompanySoftware Company, Open Soure Software Company
Software Company, Open Soure Software Company
 
Open Source 그리고 git과 github, code review
Open Source 그리고 git과 github, code reviewOpen Source 그리고 git과 github, code review
Open Source 그리고 git과 github, code review
 
국민대학교 컴퓨터프로그래밍
국민대학교 컴퓨터프로그래밍국민대학교 컴퓨터프로그래밍
국민대학교 컴퓨터프로그래밍
 
it's software!
it's software!it's software!
it's software!
 
Deview-2014-자신있는개발자에서 훌륭한개발자로
Deview-2014-자신있는개발자에서 훌륭한개발자로Deview-2014-자신있는개발자에서 훌륭한개발자로
Deview-2014-자신있는개발자에서 훌륭한개발자로
 

09.using shell

  • 1. Using Shell Minsuk Lee Hansung University, Seoul, Korea minsuk@hansung.ac.kr NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 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 variable NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 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. 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 1 NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 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 exit NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 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. Environment Variables (2) • Set, unset (environment) variables NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 8. Using alias • Rename command Temporal unalias by „‟ NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 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. 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 variables NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 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. 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. 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. 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. What you can do with scripts ? • Changing prompt – variable: PS1 `command` works ! • Changing command path NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 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. Using special Characters NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  • 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 arguments NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA