170 likes | 635 Views
Lecture 7. directory and file control your programming environment loops. Recording your screen interactions. [ fitzpatricke@baboon ~]$ script Script started, file is typescript sh-3.00$ cd lex.growth sh-3.00$ ./lexy.loop alice30.txt sh-3.00$ more stats.loop xaa.out 1893 xab.out 761
E N D
Lecture 7 directory and file control your programming environment loops
Recording your screen interactions [fitzpatricke@baboon ~]$ script Script started, file is typescript sh-3.00$ cd lex.growth sh-3.00$ ./lexy.loop alice30.txt sh-3.00$ more stats.loop xaa.out 1893 xab.out 761 xac.out 539 xad.out 407 sh-3.00$ exit exit Script done, file is typescript
The file typescript Script started on Mon Oct 31 14:13:17 2005 sh-3.00$ cd lex.growth sh-3.00$ ./lexy.loop alice30.txt rm: cannot remove `x*': No such file or directory rm: cannot remove `*.out': No such file or directory sh-3.00$ more stats.loop xaa.out 1893 xab.out 761 xac.out 539 xad.out 407 sh-3.00$ exit exit Script done on Mon Oct 31 14:13:46 2005 [ Read 14 lines ] ^G Get Help ^O WriteOut ^R Read File ^Y Prev Pg ^K Cut Text ^C Cur Pos ^X Exit ^J Justify ^W Where is ^V Next Pg ^U UnCut Text^T To Spell
Your Programming Environment- Dotfiles - ls -ashow files that determine your programming environment at login . .bash_profile .. .bashrc .Xdefaults .screenrc .bash_history .bash_logout
The alias • Aliasing allows you to call one thing another thing • example: alias guten='cd /home/data/text.data/gutenberg'
Changing rm in your .bash_profile cd ls -a cp .bash_profile .bash_profile.bak pico .bash_profile alias rm =‘rm -i’ :w :q . .bash_profile
Directory & File Control(System Utilities) cd change directory pwd print working directory mkdir dn make a directory, call it ‘dn’ ls -l -t list long list list by time cp fn1 fn2 copy fn1 to fn2 chmod o+w fn allow others to write to fn history show all past commands
echo • echoes its arguments on the screen: echo Hello world Hello world • handy for checking shorthand characters echo chap* chap1 chap2 chap3 echo chap[1-2] chap1 chap2
Environment variables .bash_profile contains variables that set up your environment $HOME stores the pathname of your home directory $PATH stores the list of directories to search for programs
$PATH /usr/kerberos/binbaboon sys admin progs /usr/local/bin nothing there! /bin progs you will recognize /usr/bin machine stuff /usr/X11R6/bin X windows stuff /home/your_username/bin Directory for your programs
Variables you know (and love?) $HOME $PATH $0, $1, $2 Moral: variables begin with a dollar sign
Putting a loop in a shell script • a loop is used to execute the same command(s) repeatedly • Syntax of a for loop for variable in list do command(s) including $variable done
Sample looping over a list #!/bin/bash #riders #generate a child’s nursery rhyme for people in gentleman lady farmer do echo This is the way the $people rides done
Output of sample loop $riders This is the way the gentleman rides This is the way the lady rides This is the way the farmer rides
Looping over a list of files ls /home/lucent/wangx/ubdb/*.in TP001.in TP049.in TP002.in TP003.in TP004.in TP005.in TP006.in TP007.in
Looping over a list of files (2) #!/bin/bash for file in /home/lucent/wangx/ubdb/*.in do tail $file >> tail.in done
problem pcl 3.727632 p 3.757441 r 3.8198171 "_o 3.934128 bcl 4.0380421 b 4.0380421 l 4.0597081 & 4.1383228 m 4.178987 , * 4.5711851 children Ccl 4.6082158 C 4.7256999 "_i 4.827867 l 4.8504529 dcl 4.8852291 d 4.9105291 r 4.950274 & 5.0135241 n 5.0482998 , * 5.5064631 Output of loop over files