Lecture 02: user environment it’s a series of tubes Hands-On Unix System Administration DeCal 2012-09-10 1 / 22
Review ❖ Shell interaction ❖ Basic commands Shell variables Shell expansion Review Pipes 2 / 22
Shell interaction e.g., bash Review ● ❖ Shell interaction there’s a prompt, type something, read ● ❖ Basic commands output, repeat Shell variables command history ● Shell expansion tab-completion Pipes ● 3 / 22
Basic commands pwd , ls , cd , mkdir , rmdir , Review ● ❖ Shell interaction touch , mv , cp , rm , echo , cat , ❖ Basic commands less , grep Shell variables whoami ( who am I) ● Shell expansion uname ( what I am I running) Pipes hostname ( where am I) date ( when ) 4 / 22
Review Shell variables ❖ Variables ❖ Shell script arguments ❖ Environment variables Shell variables ❖ Env examples ❖ Quotes Shell expansion Pipes 5 / 22
Variables case-sensitive Review ● Shell variables quotes matter (more on this later) ● ❖ Variables ❖ Shell script $ variable=’value’ arguments ● ❖ Environment $ echo "$variable" variables ❖ Env examples value ❖ Quotes Shell expansion Pipes 6 / 22
Shell script arguments $1 , $2 , $3 . . . : individual arguments Review ● Shell variables $@ , $* : all arguments ● ❖ Variables ❖ Shell script (behave differently quoted) arguments ❖ Environment $# : number of arguments variables ● ❖ Env examples $0 : name of running script ● ❖ Quotes $? : exit status of previous command ● Shell expansion Pipes 7 / 22
Environment variables Review created by init scripts (during startup), ● Shell variables by shell, or other parent processes ❖ Variables ❖ Shell script along the way arguments ❖ Environment variables inherited by child processes ❖ Env ✦ examples ❖ Quotes typically names are capitalized ✦ Shell expansion display with env or printenv , set Pipes ● with export (for bash only) 8 / 22
Env examples Review $HOME (home directory): e.g., ● Shell variables /home/jdoe ❖ Variables ❖ Shell script $PATH (directories to search for ● arguments commands): e.g., ❖ Environment variables /usr/local/bin:/usr/bin:/bin ❖ Env $PS1 (prompt display, depends on examples ● ❖ Quotes shell): e.g., \n\[\e[0;31m\]\u\[\e[m\] Shell expansion @\[\e[1;34m\]\w \[\e[2;90m\]\@ \n\[\e[m\]\[\e[0;35m\]\h\[\e[m\]\[\e[0;31m\]\$ Pipes \[\e[m\]\[\e[0;32m\] 9 / 22
Quotes no quotes: spaces and “special” Review ● Shell variables characters ( $ , * , ? , ! , ‘ , \ , ’ , " , ❖ Variables ❖ Shell script etc.) have special meanings arguments ❖ Environment double quotes: double quote and variables ● ❖ Env examples ( $ , ‘ , \ ) have special meanings ❖ Quotes single quotes: only single quote ( ’ ) ● Shell expansion Pipes has special meaning 10 / 22
Review Shell variables Shell expansion ❖ Aliases ❖ Globbing ❖ Substitution Shell expansion Pipes 11 / 22
Aliases replacement of word by another string Review ● Shell variables e.g., in bash , alias dir=’ls’ ● Shell expansion view current aliases with alias ❖ Aliases ● ❖ Globbing alternatives: functions or ❖ Substitution ● Pipes scripts/symlinks in PATH 12 / 22
Globbing parameter expansion using wildcard Review ● Shell variables character (* and ?) Shell expansion prevent with escape characters or ❖ Aliases ● ❖ Globbing quotes ❖ Substitution Pipes 13 / 22
Substitution Review output (stdout) of command in ● Shell variables backticks (‘) is substituted in Shell expansion command line ❖ Aliases ❖ Globbing useful to assign variables, e.g., ❖ Substitution ● Pipes USER=‘whoami‘ bash alternative $(...) ● 14 / 22
Review Shell variables Shell expansion Pipes ❖ Real pipes Pipes ❖ Silly words ❖ Wise words ❖ Unix pipes ❖ Standard streams ❖ Named pipes (FIFO) ❖ Network pipes (netcat) 15 / 22
President Obama at TransCanada Stillwater Pipe Yard (March 22 photo by AP via bloomberg.com )
Silly words “And again, the Review Shell variables Internet is not Shell expansion Pipes something that you just ❖ Real pipes ❖ Silly words ❖ Wise words dump something on. It’s ❖ Unix pipes ❖ Standard streams not a big truck. It’s a ❖ Named pipes (FIFO) ❖ Network series of tubes .” pipes (netcat) (Sen Ted Stevens, R-AK) 17 / 22
Wise words “This is the Unix philosophy. Write Review Shell variables programs that do one thing and do Shell expansion Pipes it well. Write programs to work ❖ Real pipes ❖ Silly words together. Write programs to ❖ Wise words ❖ Unix pipes handle text streams , because that ❖ Standard streams is a universal interface .” ❖ Named pipes (FIFO) ❖ Network (Doug McIlroy, inventor of Unix pipes) pipes (netcat) 18 / 22
Unix pipes Review Shell variables Shell expansion Pipes ❖ Real pipes ❖ Silly words ❖ Wise words ❖ Unix pipes ❖ Standard streams ❖ Named pipes (FIFO) ❖ Network pipes (netcat) http://en.wikipedia.org/ wiki/File:Pipeline.svg 19 / 22
Standard streams Review standard input ( stdin ): text going into ● Shell variables program (read), typically TTY unless Shell expansion redirected Pipes ❖ Real pipes standard output ( stdout ): text going ● ❖ Silly words ❖ Wise words out of program (write), typically TTY ❖ Unix pipes ❖ Standard unless redirected streams ❖ Named pipes standard error ( stderr ): (FIFO) ● ❖ Network error/diagnostic text output, not pipes (netcat) redirected 20 / 22
Named pipes (FIFO) named in contrast to anonymous ones Review ● Shell variables created by shell Shell expansion special file created using mkfifo ● Pipes ❖ Real pipes can be used as a temporary file ● ❖ Silly words ❖ Wise words ❖ Unix pipes ❖ Standard streams ❖ Named pipes (FIFO) ❖ Network pipes (netcat) 21 / 22
Network pipes (netcat) Imagine the possibilities: Review Shell variables dd ● Shell expansion Pipes gzip ● ❖ Real pipes ❖ Silly words ❖ Wise words ❖ Unix pipes ❖ Standard streams ❖ Named pipes (FIFO) ❖ Network pipes (netcat) 22 / 22
Recommend
More recommend