120 likes | 315 Views
BASH (Bourne Again SHell) Associate Professor Quincy Wu solomon@2012.ipv6.club.tw National Chi Nan University Linux User Group 2012 Summer Training. Unix Shell. In Unix, a shell is a command-line interface which interprets input from users and take corresponding actions. User. Shell.
E N D
BASH(Bourne Again SHell)Associate Professor Quincy Wusolomon@2012.ipv6.club.twNational Chi Nan UniversityLinux User Group 2012 Summer Training
Unix Shell • In Unix, a shell is a command-line interface which interprets input from users and take corresponding actions. User Shell Operating System Hardware
History of Unix Shells • sh – Bourne shell • written by Stephen Bourne at AT&T as the original Unix command line interpreter • csh – C Shell • History of commands • C-like syntax • tcsh – Turbo C Shell • Enhanced C shell. Allow users to navigate through the history of commands with the arrow keys. • bash – Bourne Again Shell • Same syntax as Bourne shell, combining the advanced features in csh and tcsh. set a=3 set b=4 if ($a == $b) then echo "a is larger" else echo "b is larger" endif
Topics • Command-line interface • Environment variables • Shell script syntax • Login files
Command-Line Interface (CLI) • Basic Commands • I/O re-direction • Pipeline • Wildcard • Filename completion • History • Substitution • Search through the history of commands
Remote Login with PuTTY • Download PuTTY • Connect to ms11.voip.edu.tw (port 3261),or the Linux machine which you just installed.
Basic Commands • date • cal • cal 10 1911 • who • who am i • cat • cat > filename • cat -n • tail • tail -3 • head • wc • ls • ls -l • ls -lt • ls -lR • sort • sort -r • sort -n • sort +3 • grep • grep -v • grep -i • mv • rm
I/O Redirection • cat > a.cpp #include <iostream> using std::cin; using std::cout; using std::endl; main() { int i, j; for (i=1; i<=5; i++) { cin >> j; cout << i << '\t' << j << endl; } return 0; } • cat > a.dat 98 32 45 26 83 ^D • g++ a.cpp -o a.exe • a.exe • a.exe < a.dat • a.exe < b.dat • a.exe < a.dat > a • cat < a
Pipeline • Connect the output of one program to the input of another program without any temporary file. • who > aaa • sort < aaa • who | sort • who | wc -l • who | grep lilykoko | wc
Wildcard Characters • ls • ls a* • ls a? • ls a[0-9] • ls a[135] • rm a*
Filename Completion • Press <TAB> to complete a command or a filename. • ls /bin/sl <TAB> • ls /bin/sleep • When there are multiple choices, press <TAB> will expand to the common prefix, then press <TAB> twice will list all choices. • ls /usr/local/l <TAB>
History of Commands • history • history -20 • alias h=‘history -20’ • !3 • !! • !c • !3:s/cpp/CPP/ • <ESC>-<.>, <ESC>-<_>, !!:$ • Arrow keys (Up, Down, Left, Right) • Ctrl-A, Ctrl-E, Ctrl-K, Ctrl-W, Ctrl-C • <ESC>-<D>, <ESC>-<BackSpace> • Search: Ctrl-R