Even experts like me forget line and word erase control characters (09.02)
Watch out for trying to create files by using wildcards.... See 1.16 again.
09.05 - I've not used this very much. It should work on our workstations and servers. However I'd avoid it in scripts which may be executed by the original 'sh' Bourned Shell! Try these out! Use if you want. But not on the final exam.
09.06 May be useful on our workstations, but not on a non-Linux server. As a rule I find editting previous commnads like this a bit difficult. Not on exam.
09.07 New: I've never used these (I use commands to edit strings... more later on this. Will not be on the final exam.
You can skip 09.08 to 09.10 if you wish, but I've known people to get very attached to this.
In the Korn shell: if you define EDITOR and VISUAL [ 06.variables.html ] [ 06.variables.html ] Then the ESC character will let you edit your history using your favorite visual editor. For example, ESC k, shows the previous line and you can tap Return and re-execute it.
The fantastic for loop.... but skip 09.11 (unless you like csh). The ksh/sh/bash format(9.12) is IMHO(In My Humble Opinion) easier to type and read:
for file in /usr/fran/report /usr/rob/file3 /usr/rob/file2
do cat -t -v $file | pg
done
Study and experiment with the content of 09.12. I use it a lot.
for f in notes/*
do cat template >$f
doneor
for n in 0 1 2 3 4
do
for m in 0 1 2 3 4 5 6 7 8 9
do
echo $n$m > notes/$n$m
done
done
09:13: Vital information! Use it all the time...
09:14: "Here documents" I use this every 2 minutes, 24 hours a day, and 7 days a week! Seriously: I have a daemon running to sort my EMail and part of the script looks like this
mailx <<++++++
s/XXXX mail/junk
d/junk
s/cs360 todo/cs360
s/cs360 cs360/received
d/cs360and so on until
++++++
To see the full thing in its horror and glory, rlogin into Blaze and look inside
~dick/bin/sort.my.mail
09.15: I like developing throw-away scripts. Especially as you can execute them without leaving the editor!
:!sh %executes the sh shell with the file name as an argumnet. For testing
:sh -x %
The incredible back-quotation marks. Lets you compute a part of a command! (09.16).
09.17.... shows you lists of files in a command.... suppose you had a list of all the people in this class in file "roster", what would the following do:
mailx `cat roster`
09.18. Hmm new in bash. Not in final. But looks like I might use it!
09.19. Type ahead
09.20 Introduces my favorite technique "while read line; do something; done"
09.21. When you don't have "xargs" you can get the same effect by a one line Korn shell loop. Replace
xargs command <fromby
while read args; do command $args; done <from
Skip(?) 09.22 and 09.23
09.24 - I think the book may be a bit too clever here. I use the following.
ls -ltr|tail -20to get the last 20 files that were modified. I put it in a file
~dick/bin/latestand made it public and executable. Nice and useful. Or try
ls -ltr|grep "Jan 16"for those modified on that day.
On the other hand I regularly save a complete directory into a file:
ls >dirand then edit it to get a list of files for future work, or even into commands to be obeyed. One case is when I transfer files from my home PC to here via a DOS disk. The dir file is edited to be the commands that reconstruct the UNIX files names from their DOS counterparts.... then I dump that file on the disk as well.
Notice the tricks with grep/vi/sed/sort for generating a list of files that contain a text string....
Skip 09.25... However somewhere I have a repeat n times script...
(expect): 09.26. A new feature and tool that I have yet to master...
Paul Tonning uses it a lot. It won't be on the final.
vi [a-e]What happens?
for f in a b c d e f;do echo >$f; doneWhat happens
for f in a b c d e f do echo >$f; doneWhat happens
for f in *.txt; do echo $f
cat >>$f
done
What is output by this Korn shell command when environment variable V has value "date" on January the 15th 1996?
echo 'V' '$V' "V" "$V" V `$V`
V date V date V date?
V $V V date V date?
V $V V $V V date?
V $V V date V Jan 15 1996....?
V $V V $V V Jan 15 1996....?
V date V date V Jan 15 1996....?
ls -ltr | tail
ls -ltr | grep tail
ls -ltr >/tmp/mine; grep tail /tmp/mine?
Submit Your Notes Here
To earn credit for completing this part of the course
you need to send me a short list of things you have learned.
A simple way to do this is to
follow this
[click here
if you can fill this hole]
link and fill in the form.