150 likes | 346 Views
UNIX Shell. Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn. Where is a shell ?. C programs scripts. Users. Shells & Utilities. ksh, bash, gcc, find. open(), fork(), Exec(),. kernel. Hardware. What is a shell ?. To users:
E N D
UNIX Shell Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology hoai@cse.hcmut.edu.vn
Where is a shell ? C programs scripts Users Shells & Utilities ksh, bash, gcc, find open(), fork(), Exec(), kernel Hardware
What is a shell ? • To users: • A user interface to UNIX • Many shells • Thought harder to use than GUI, but not • Harder to learn • And definition • Program to make the system understand commands (also called command intepreter)
Purpose of shell • Interactive use • Customization of UNIX session • Environment variables • Startup files • Programming • Shell scripts: executing a series of commands
Favourite shells • GNU Project’s Bash (Bourne-Again SHell) (bash) • Thompson shell → Bourne shell → Bash • Most popular • Command-line editing • Korn shell (ksh) • “Tenex” C shell (tcsh) • C programming style
Shell for individual • /etc/passwd hoai:x:556:500:Tran Van Hoai:/home/hoai:/bin/bash • Default shell for interactive use • “which” to find a path of a shell hoai@moon:~> which tcsh /usr/bin/tcsh hoai@moon:~> which bash /bin/bash • “exec” to change shell hoai@moon:~> exec bash
Interactive use • Command history • Command-line editing • File/command expansion • Job control
Shell scripting • Script = set of shell and UNIX commands • Text file • Executable program • Automating repetitive task and administrative tools
hoai@moon:~> ls -l lib.tar.gz -rwx------ 1 hoai users 80738389 2005-09-27 17:09 lib.tar.gz command arguments Simple commands • Sequence of non-blank arguments separated by blanks or tabs • First argument = name of command
Types of arguments • Options/Flags • -X or –longname • Parameters • Strings, file names • Depends on command $ tar –c –v –f archive.tar main.c main.h
Getting help on UNIX • “man”: display manual page • Manual entry organization • Commands • System calls • Subroutines • Special files • File format and conventions • Games
Security fundamentals • Multiple users identified by a number and and name hoai:x:556:500:Tran Van Hoai:/home/hoai:/bin/bash • superuser = (id 0, name root) • Set of users can form a group • A user can belong to several groups
How are users/groups used? • Used to determine if file or process operations can be performed • Can a given file be read? Written to ? • Can this program be run? • Can I use this piece of hardward? • Can I stop a particular running process?
hoai@moon:~> ls -l lib.tar.gz -rwx------ 1 hoai users 80738389 2005-09-27 17:09 lib.tar.gz read write execute Example
Unix file system is NEXT