BASH Erick, David © Sekolah Tinggi Teknik Surabaya 1
2 Shell Kernel User Input
» Bourne-Again Shell » Primary Shell for GNU/Linux and MAC OS X » Also available in Solaris and various BSD Systems » Can also be compiled in other Unix system 3 © Sekolah Tinggi Teknik Surabaya
Bourne Shell (sh) C Shell (csh) Korn Shell (ksh) Bourne- Again Shell (bash) 4 © Sekolah Tinggi Teknik Surabaya
» Input/output redirection » Wildcard characters for filename abbreviation » Shell variables and options for customizing the environment » A built-in command set for writing shell programs » Shell functions, for modularizing tasks within a shell program » Job control » Command-line editing (using the command syntax of either vi or Emacs) 5 © Sekolah Tinggi Teknik Surabaya
» Access to previous commands (command history) » Integer arithmetic » Arrays and arithmetic expressions » Command-name abbreviation (aliasing) » Upwards compliance with POSIX » Internationalization facilities » An arithmetic for loop 6 © Sekolah Tinggi Teknik Surabaya
» Special files » Filename Metacharacters » Brace Expansion » Quoting » Command Forms » Redirection Forms 7 © Sekolah Tinggi Teknik Surabaya
» Startup Files ˃ /etc/profile. Executed automatically at login ˃ The first file found from this list: ~/.bash_profile, ~/.bash_login, or ~/.profile. Executed automatically at login. 8 © Sekolah Tinggi Teknik Surabaya
9
10 © Sekolah Tinggi Teknik Surabaya
11 © Sekolah Tinggi Teknik Surabaya
12 © Sekolah Tinggi Teknik Surabaya
13 © Sekolah Tinggi Teknik Surabaya
14 © Sekolah Tinggi Teknik Surabaya
» Everything between " and " is taken literally, except for the following characters that keep their special meaning: ˃$ -- Variable substitution ˃` -- command substitution » Everything between ' and ' is taken literally » The character following a \ is taken literally. Use within " " to escape ", $, and `. Often used to escape itself, spaces, or newlines 15 © Sekolah Tinggi Teknik Surabaya
16 © Sekolah Tinggi Teknik Surabaya
» cmd & ˃Execute cmd in background » cmd1 ; cmd2 ˃Command sequence; execute multiple cmds on the same line » cmd1 | cmd2 ˃Pipe; use output from cmd1 as input to cmd2 » cmd1 `cmd2` ˃Command substitution; use cmd2 output as arguments to cmd1 17 © Sekolah Tinggi Teknik Surabaya
» cmd1 && cmd2 ˃AND; execute cmd1 and then (if cmd1 succeeds) cmd2. This is a “short circuit” operation: cmd2 is never executed if cmd1 fails. » cmd1 || cmd2 ˃OR; execute either cmd1 or (if cmd1 fails) cmd2. This is a “short circuit” operation; cmd2 is never executed if cmd1 succeeds. 18 © Sekolah Tinggi Teknik Surabaya
19 © Sekolah Tinggi Teknik Surabaya
CommandExplanation cdChange directory echoPrint command-line arguments to standard output exitExit the shell script historyPrint command-line history pwdPrint working directory lsList files catList file content to standard output revReverse each line of a file and output to standard output 20 © Sekolah Tinggi Teknik Surabaya
CommandExplanation cpCopy a file mvMove a file rmRemove a file rmdirRemove a directory mkdirMake a directory chmodChange the attributes of an existing file manManual pages 21 © Sekolah Tinggi Teknik Surabaya
» Arnold Robbins, Bash Pocket Reference, O’Reilly, 2010 » Basic Commands, c.html c.html 22 © Sekolah Tinggi Teknik Surabaya