phaedrus@eneevax.UUCP (04/22/84)
What I want it do is to take the arguements (filenames) and just show the first 20 lines of the file and then ask "Would you like me to remove (filename)?", if yes then remove it, if no don't. The error message I keep getting is, "unexpected newline on line 10". This is the line with the "if" statement. #! /bin/sh for i do set $ANSWER=no head -20 $i echo -n 'Would you like me to remove ' echo -n "$i" echo ' ?' set $ANSWER=$< if [ $ANSWER = yes -o $ANSWER = y ] then rm $i fi done Thanks in advance, Pravin Kumar -- From the brainless and rotted body of the sophist. ARPA: phaedrus%eneevax%umcp-cs@CSNet-Relay BITNET: phaedrus@UMDC UUCP: {seismo,allegra,brl-bmd}!umcp-cs!eneevax!phaedrus
rpw3@fortune.UUCP (04/24/84)
#R:eneevax:-11200:fortune:26900051:000:4575 fortune!rpw3 Apr 23 14:40:00 1984 Tutorial time, netters. All wizards "n" (or "j", as appropriate). --------------------------------------------------------------------- There is quite a lot wrong with your script, but most of it comes from (1) mixing 'csh' and 'sh' syntax, and (2) not having proper syntax for shell variables. +-------------------- | The error message I keep getting is, "unexpected newline on line 10". | This is the line with the "if" statement. +-------------------- I think it's the line before the "if", but let's look at the whole thing closely. +-------------------- | #! /bin/sh +-------------------- You asked for /bin/sh, so we'd better stick with /bin/sh syntax, not /bin/csh. +-------------------- | for i | do | set $ANSWER=no +-------------------- First serious problem: "ANSWER" is a variable, "$ANSWER" is its VALUE. Since ANSWER hasn't been used previously, it is null. Hence this line actually says "set =no" which (since no valid hyphen-option is seen), sets shell variable "1" (value $1) to the word "=no", and clears (sets to null) the rest of the arguments ($2, $3, &c.). (See the section on the "set" command in the "sh" man page.) However, the range of the "for" loop has already been evaluated, so this will not truncate the loop early. As you will see below, this line is not even needed. +-------------------- | head -20 $i | echo -n 'Would you like me to remove ' | echo -n "$i" | echo ' ?' | set $ANSWER=$< +-------------------- Two problems: (1) again, we have $ANSWER where ANSWER is needed, but (2) this is not how /bin/sh reads from the keyboard. This should be "read ANSWER". (For /bin/csh, it should be "set ANSWER=$<") (Whichever shell you use, reading the answer in will overwrite the previous value of ANSWER, so the earlier "ANSWER=no" has no effect beyond this point, and therefore that whole line should be left out.) This is probably where your error message is occurring, NOT on the "if" line. Because of the spurious "$", the shell saw "set =$<" (the variable ANSWER is still null...), and parsed this as "set =$ < [missing filename]". It then complained because you didn't finish supplying a filename after starting input redirection "<". The "$" is not special here, since "<" is not one of the characters that the Bourne Shell knows about after "$". +-------------------- | if [ $ANSWER = yes -o $ANSWER = y ] +-------------------- What happens if a user types just <carriage-return> to your question? ANSWER will again be null, and the "if" will read "if [ = yes -o = y ]" which will produce the error "test: unknown operator 'yes'". (Since the "[" is a link to the program "test".) To guard against this, always (1) use double-quotes around your read-in strings and (2) pad such strings with a leading character to keep them from ever being null: if [ "X$ANSWER" = Xyes -o "X$ANSWER" = Xye -o "X$ANSWER" = Xy ] By the way, since "[" runs the "test" program, experienced shell programmers will use the "case" construct for simple pattern matching, as in: echo -n 'Question? ' read answer case "X$answer" in Xy | Xye | Xyes) ... whatever you want to do if yes ... ;; *) ... whatever you want to do if NOT yes ... ;; esac +-------------------- | then | rm $i | fi | done | Thanks in advance, | Pravin Kumar +-------------------- All in all, I suggest a good slow careful reading of the "sh" man page, followed by the purchase of Kernighan & Pike's "The UNIX Progarmming Environment", and reading and PRACTICING of the shell programming examples found there. Rob Warnock UUCP: {ihnp4,ucbvax!amd70,hpda,harpo,sri-unix,allegra}!fortune!rpw3 DDD: (415)595-8444 USPS: Fortune Systems Corp, 101 Twin Dolphin Drive, Redwood City, CA 94065 p.s. A slightly cleaned up version of your script follows: +-------------------- | : 'vrm - verbose "rm" - Shows first of each file, asks if o.k., and removes' | case $# in | 0) | echo 'Usage: vrm files...' | exit | ;; | esac | for i | do | echo "----- $i -----" | head -20 $i | echo '-----' | echo -n "remove $i (yes, no)? " | read answer | case "X$answer" in | Xy | Xye | Xyes) | rm $i | echo "$i removed" | ;; | *) | echo "$i not removed" | ;; | esac | | done +-------------------- p.p.s. Note that everything after the "head -20" can be replaced with "rm -i $i". +-------------------- | : 'vrm - verbose "rm" - Shows first of each file, then calls "rm -i"' | case $# in | 0) | echo 'Usage: vrm files...' | exit | ;; | esac | for i | do | echo "----- $i -----" | head -20 $i | echo '-----' | rm -i $i | done +--------------------
jas@drutx.UUCP (ShanklandJA) (04/24/84)
> To guard against this, always (1) use double-quotes around > your read-in strings and (2) pad such strings with a leading > character to keep them from ever being null: > if [ "X$ANSWER" = Xyes -o "X$ANSWER" = Xye -o "X$ANSWER" = Xy ] I've always wondered about this curious custom of prefixing strings with X (or whatever) to keep them from being null. Why? The System V Bourne shell finds null strings perfectly acceptable; of course, they have to be quoted, because the empty string is not the same as no string at all. In any case, I find that: if [ "$ANSWER" = yes -o "$ANSWER" = ye -o "$ANSWER" = y ] works just fine, even when $ANSWER is null. Those X's look ugly to me. Am I missing something? Jim Shankland ..!ihnp4!druxy!jas
laman@sdcsvax.UUCP (04/25/84)
What if ANSWER is "-o"... That's whay there the 'X' was added to the beginning of the variable! Mike Laman UUCP: {ucbvax,philabs,sdccsu3,sdcsla}!sdcsvax!laman
rpw3@fortune.UUCP (04/26/84)
#R:eneevax:-11200:fortune:26900052:000:849 fortune!rpw3 Apr 25 23:31:00 1984 Re: X$var vs. "$var" (*blush*) Oops, seems I am exhibiting what has been called "programmer's superstition". Back when I was learning the Shell for the first time, somebody showed me the X$var style, and I learned it that way. Having just tried null (but present) strings on both the "if" and the "case" commands (yes, they work), I will probably cease this X-ing. (Question for the net: Is there ANY time where X$var is preferable to "$var"?) The person who originally demo'd to me was probably just a bit lazy about typing the quotes (although X$var is not significantly easier for me to type than "$var"). Or else HE learned it from the person who taught him... ;-} Rob Warnock UUCP: {ihnp4,ucbvax!amd70,hpda,harpo,sri-unix,allegra}!fortune!rpw3 DDD: (415)595-8444 USPS: Fortune Systems Corp, 101 Twin Dolphin Drive, Redwood City, CA 94065
jeff@aids-unix.ARPA (04/26/84)
From: Jeff Dean <jeff@aids-unix.ARPA> The Bourne shell does not recognize the '$<' construct for reading a line from the standard input. See the 'read' command on the 'sh' manual page.
ignatz@ihuxx.UUCP (Dave Ihnat, Chicago, IL) (04/27/84)
Esp. RE: X$var vs. "$var": This solution probably came from the example used in the USG (now WE) Unix(Tm, of course) manual for the expr(1) command. On the very last page of the man entry, they address the problem of null strings and the shell getting to them as follows: if a='=' expr $a = '=' then looks like expr = = = and fails! (note that expr "$a" = '=' also fails) Thus, they suggest expr X$a = X= to get around the problem. Dave Ihnat ihuxx!ignatz
johnson@hardy.DEC (MATT JOHNSON*381-1121*ZK01-3/E33) (11/07/84)
Does anyone do direct phototypesetting of text formatted with T-roff (sp?) under UNIX? I'd be grateful for any leads, MATT
ron@leopard.UUCP (11/09/84)
AM Varytyper (sp?) located in East Hanover NJ does phototype setting from troff. I beleive they are also working on a device independent troff. AM has been around for a while and most of their typesetters are computer driven by one of the 68000 family, running SYS V. -- ...{leopard|lion}!ron Ron Bach Rumors Mongered here. Bell Communications Research These are my opinions not the management's. 331 Newman Springs Road They have to get their own. Red Bank, NJ 07701
david@ukma.UUCP (David Herron) (11/13/84)
^ From: johnson@hardy.DEC (MATT JOHNSON*381-1121*ZK01-3/E33) ^ Subject: Help! ^ Message-ID: <4153@decwrl.UUCP> ^ Does anyone do direct phototypesetting of text formatted ^ with T-roff (sp?) under UNIX? ^ I'd be grateful for any leads, ^ MATT It is hard to tell exactly what you want to know. There is a company ("Accucom") which takes tapes with troff files on them and typesets the text on an APS-5 phototypesetter. (I don't know why they won't accept things through uucp. If they did it would improve the turnaround time.) (They use an "enhanced version" of ditroff for this). I forget the exact price they charge but it's cheaper than buying a typesetter. For our purposes though, a laser printer is fine. Accucom, Bill Fullilove, Account Representative (503) 684-2850 or 1-800-accucom 9730 S.W. Cascade Blvd. Suite 220 Tigard, OR 97223 I talked to them once and they seemed reasonable. The tape gets to them and the typeset output back by Federal Express, to it is a 2 day turnaround. ----------------------------------------- David Herron Phone: (606) 257-4244 (phone will be answered as "Vax Lab", usually). (606) 254-7820 /------- Arpa-Net unmvax----\ / research >---/----------------/----------- anlams!ukma!david boulder---/ / decvax!ucbvax ---/ (or cbosgd!hasmed!qusavx!ukma!david) For arpa-net, anlams has the name ANL-MCS. (i.e. use "ukma!david@ANL-MCS"). I have been having intermittent problems with this address though.