1 / 17

Lecture 7

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

Jimmy
Download Presentation

Lecture 7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 7 directory and file control your programming environment loops

  2. 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

  3. 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

  4. Your Programming Environment- Dotfiles - ls -ashow files that determine your programming environment at login . .bash_profile .. .bashrc .Xdefaults .screenrc .bash_history .bash_logout

  5. The alias • Aliasing allows you to call one thing another thing • example: alias guten='cd /home/data/text.data/gutenberg'

  6. 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

  7. 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

  8. 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

  9. 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

  10. $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

  11. Variables you know (and love?) $HOME $PATH $0, $1, $2 Moral: variables begin with a dollar sign

  12. 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

  13. 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

  14. 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

  15. 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

  16. Looping over a list of files (2) #!/bin/bash for file in /home/lucent/wangx/ubdb/*.in do tail $file >> tail.in done

  17. 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

More Related