Lecture 7
Download
1 / 17

Lecture 7 - PowerPoint PPT Presentation


  • 437 Views
  • Updated On :

Lecture 7. directory and file control your programming environment loops. Recording your screen interactions. [ [email protected] ~]$ 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

Related searches for Lecture 7

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Lecture 7' - Jimmy


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Lecture 7 l.jpg

Lecture 7

directory and file control

your programming environment

loops


Recording your screen interactions l.jpg
Recording your screen interactions

[[email protected] ~]$ 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 l.jpg
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 l.jpg
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 l.jpg
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 l.jpg
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 l.jpg
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


Slide8 l.jpg
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 l.jpg
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


Slide10 l.jpg
$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 l.jpg
Variables you know (and love?)

$HOME

$PATH

$0, $1, $2

Moral: variables begin with a dollar sign


Putting a loop in a shell script l.jpg
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 l.jpg
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 l.jpg
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 l.jpg
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 l.jpg
Looping over a list of files (2)

#!/bin/bash

for file in /home/lucent/wangx/ubdb/*.in

do

tail $file >> tail.in

done


Output of loop over files l.jpg

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


ad