170 likes | 353 Views
Welcome to CSE 4251. Description: Students will learn how to use the UNIX programming environment effectively to orchestrate processes and find information in files using basic shell programming methods. In addition, students will learn programming basics for utilities such as grep and make .
E N D
Welcome to CSE 4251 • Description: Students will learn how to use the UNIX programming environment effectively to orchestrate processes and find information in files using basic shell programming methods. In addition, students will learn programming basics for utilities such as grep and make. • Level and Credits : U1 • Other: grading, labs, etc : • See web http://www.cse.ohio-state.edu/~lido/teaching/cse4251/
Welcome to CSE4251 • Name: Dong Li • Email: lido@cse.ohio-state.edu • Classroom: Bolz 0311 • Class Time: Monday 9:10am – 10:05am • Office : DL274 • Telephone: 614-465-6899 • Office Hours: 10:05am-11:30am
Lecture 1: Introduction to Unix Shell Brief Unix History Running Model and System Calls Unix Shell & Flavor
Unix History • The first version of Unix came from AT&T in the early 1970s (Unix is old!). 1991
Unix Motivation • Unix was developed by programmers and for programmers. • Unix is designed so that users can extend the functionality • To build new tools easily and efficiently • To customize the shell and user interface. • To string together a series of Unix commands to create new functionality. • To create custom commands that do exactly what we want.
Running Model • User Mode • A process running in this mode can’t access kernel data structures and procedures • Kernel Mode • A process running in this mode can access kernel data structures and procedures • System call • Can be looked as the interface between user mode and kernel mode
Creating Processes • fork() • Create a duplicate of the calling process • exec() • Create a duplicate of the calling process • Load a executable program whose name is one of arguments of exec() into the address space of the new process • wait()- Cause a parent process to sleep until one of its child processes terminates • exit()
What is Shell? • Shell is • Command Interpreter that turns text that you type (at the command line) in to actions: • Shell is a process; • User Interface: take the command from user • Programming Shell can do • Customization of a Unix session • Scripting
Customization of a Session • Each shell supports some customization. • User prompt • Where to find mail • Shortcuts (alias) • The customization takes place in startup files • Startup files are read by the shell when it starts up • The Startup files can differ for different shell
Startup files • sh,ksh: /etc/profile (system defaults) ~/.profile • bash: ~/.bash_profile ~/.bashrc ~/.bash_logout • csh: • ~/.login: executed when you logon • ~/.cshrc: executed when a new shell is spawned • ~/.logout: executed at logout
Flavors of Unix Shells • Two main flavors of Unix Shells • Bourne (or Standard Shell): sh, ksh, bash, zsh • AT&T shell • Fast • $ for command prompt • C shell : csh, tcsh • Berkley Shell • better for user customization and scripting • %, > for command prompt • To check shell: • % echo $SHELL (shell is a pre-defined variable) • To switch shell: • % exec shellname (e.g., % exec bash)
Popular Shells • sh Bourne Shell • ksh Korn Shell • csh,tcsh C Shell (for this course) • bash Bourne-Again Shell
Your Best Friend • % man command (e.g., % man ls) • shows information about the command • usually space or ↓ for more information • q to quit • % man man
Some Common Commands • ls –l • mv src dst // rename a file • rm file // delete files or directories • cp src dst // copy files • mail • write sb // send an message to sb • lpr // print something • wc file // word counting for a file • tail –n file // print out the last n lines of file • tail +n file // print out file starting from nth line • mkdir dir_name // create a directory • rmdir dir_name // delete a directory
Recommended Reading • Chapter 1, sections 1.1 – 1.5