HDTenEightyP/NetNews huggingface dataset:
From: nurban@tjhsst.vak12ed.edu (Nathan Urban)
Subject: Re: Shell Scripts vs. C programs
Summary: is C so non-portable?
Keywords: shell script, C
Organization: Virginia's Public Education Network (Fairfax)
Date: Tue, 01 Sep 92 06:29:06 GMT

In article <1992Sep1.044434.7193@news.acns.nwu.edu> navarra@casbah.acns.nwu.edu (John Navarra) writes:

>For one, most [ba|k|z]sh scripts will run in sh and vice versa. And, if you 
>need to, you can always get shell X and compile it on your machine. This is
>*usually* easier than rewriting C-code to accomodate your OS. 

...

>	And translating your C code using compiler X to OS Y is any
>easier? Perhaps you are thinking of Csh? Then, yeah, you suck. 

>-tms
>-- 
>You can get further with a kind word | You can get further with a kind word
>and a gun than a kind word alone.    | and a phaser than a kind word and a gun.
>          --al capone                |           -- John Navarra
>=======From the Lab of the MaD ScIenTIst....navarra@casbah.acns.nwu.edu========


It seems to me that most tasks that you would write a shell script for
could be implemented in very portable C without worrying too much about
OS quirks if one so desired.


-- 
-------------------------------------------------------
Nathan Urban                  nurban@tjhsst.vak12ed.edu
Thomas Jefferson High School for Science and Technology
-------------------------------------------------------
Newsgroups: comp.unix.shell
From: msb@sq.sq.com (Mark Brader)
Subject: Re: Help with directories!
Followup-To: poster
Organization: SoftQuad Inc., Toronto, Canada
Date: Tue, 25 Aug 92 22:40:49 GMT

> > But we discussed it ad nauseum just five days ago!!
> 
> This guy just happened to ask a question that was recently discussed.
> He had no way of knowing that, since he's a new reader,

Then he shouldn't have been posting.  *That's* the point.  That's why
FAQs are posted monthly rather than weekly or daily -- standard netiquette
calls for you to read a group for a while before opening your mouth in it.

> and so he didn't deserve the flame.

Indeed we cannot assume that.  It might be his *newsadmin* who deserves
the flame, for not pointing him to the periodically posted articles in
news.announce.newusers.  (This doesn't have to require a personal talk
with each new user; at a large site, it could be done automatically when
new accounts with Usenet access are created, or when the news software is
first used, or the like.)

In the article "A Primer on How to Work With the Usenet Community", he
would have read the following:

|  Be familiar with the group you are posting to before you post!  You 
|  shouldn't post to groups you do not read, or post to groups you've
|  only read a few articles from -- you may not be familiar with the on-going
|  conventions and themes of the group.  One normally does not join
|  a conversation by just walking up and talking.  Instead, you listen
|  first and then join in if you have something pertinent to contribute.

If these words aren't familiar to you, it's time *you* reviewed the
documents for new users.

And, of course, if you *are* going to complain about a newcomer, it's as
well to politely quote the above passage, rather than flaming.

This is now off-topic for the newsgroup, so followups are directed to email.
-- 
Mark Brader		  It never occurred to me that a living person could be
SoftQuad Inc., Toronto	   used as a blowtorch, but we admit human beings are a
utzoo!sq!msb, msb@sq.com    bit special, don't we? -- Hal Clement: STILL RIVER

This article is in the public domain.
Newsgroups: comp.unix.shell,comp.unix.questions
From: Tom Christiansen <tchrist@convex.COM>
Subject: Re: Shell Scripts vs. C programs
Originator: tchrist@pixel.convex.com
Date: Mon, 31 Aug 1992 23:55:08 GMT
Reply-To: tchrist@convex.COM (Tom Christiansen)
Organization: Convex Computer Corporation, Colorado Springs, CO
Keywords: shell script, C
X-Disclaimer: This message was written by a user at CONVEX Computer
              Corp. The opinions expressed are those of the user and
              not necessarily those of CONVEX.

From the keyboard of ajayshah@almaak.usc.edu (Ajay Shah):
:When the script gets too large, it's easier to debug C instead
:of sh/sed/awk.  There are better debugging tools for C (a
:weakness of the sh/sed/awk paradigm which sounds fixable to me).

I have to admit that there are times I write in perl instead
of sh/sed/awk just because perl has a symbolic debugger for
it and those don't.

--tom
-- 
    Tom Christiansen      tchrist@convex.com      convex!tchrist
Steinbach's Guideline for Systems Programming
        Never test for an error condition you don't know how to
        handle.
From: tchrist@convex.COM (Tom Christiansen)
Newsgroups: comp.unix.shell
Subject: Re: Shell Scripts vs. C programs
Date: 2 Sep 92 14:31:54 GMT
Reply-To: tchrist@convex.COM (Tom Christiansen)
Organization: Convex Computer Corporation, Colorado Springs, CO
Originator: tchrist@pixel.convex.com
X-Disclaimer: This message was written by a user at CONVEX Computer
              Corp. The opinions expressed are those of the user and
              not necessarily those of CONVEX.

From the keyboard of friedman@gnu.ai.mit.edu (Noah Friedman):
:The reason why people complain about perl
:having the kitchen sink is that it has no uniform design; instead there is
:a grab bag of features that look hastily adopted from other programs like
:sed, awk, and grep, none of which are very orthogonal.  

Orthogonality was not a design goal. :-)  No, really -- but one design
goal *was* an easy migration path for the Unix world.  That means having
what you're used to in C, sh, awk, sed, and several other things as
you're use to them.  The idea was that if you already knew how to
do something in tr or sed or whatnot, you should be able to leverage
this knowledge without having to learn a new syntax entirely.

:There are various
:annoying context-dependent misfeatures in perl as well, and
:multi-dimensional/nested arrays are cumbersome (the associate array
:features in awk are much easier to deal with).  

You're certainly right about nested arrays being cumbersome.  In fact,
this and not the lack of minimalism is far and above my biggest 
complaint.  I have several schemes for achieving nested, recursive,
or record-like data structures, but all are synthesized.  This may be
fixed in the next release. :-)

But perl's associative arrays are really quite the same as awk's,
and its multi-dimensional array *emulation* is also like awk's.

:Perl also suffers from
:being too redundant...

You say "too" redundant.  Is some redundancy ok?  How much?  Who
draws the line?  Even C has redundancy in having three forms of
looping, the comma getting used as a statement separator, etc.

:The idea of function calls being lvalues I find
:to be unaesthetic as well.  

It is a strange thing.  But it's so you can get at single characters
or single bits in a long string.  It's only in these two accessor
pseudofunctions:

    substr($var, $pos, 3) = 'red';
    vec($var, $bitindex, 1) = 1;

:   Incidentally, I have a public domain Scheme implementation written in
:Perl.  It's missing continuations among other things, but it's still rather
:interesting... Anyone have any idea who wrote it?  There wasn't any author
:listed in the copy I found.

Try Felix Lee <flee@guardian.cs.psu.edu>


--tom
-- 
    Tom Christiansen      tchrist@convex.com      convex!tchrist

It is the business of little minds to shrink.
                -- Carl Sandburg
Xref: sparky comp.unix.shell:3712 comp.unix.questions:10568
From: nurban@tjhsst.vak12ed.edu (Nathan Urban)
Subject: Re: script for eliminating newsarticle's headers
Organization: Virginia's Public Education Network (Fairfax)
Distribution: usa
Date: Fri, 04 Sep 92 01:38:04 GMT

In article <5397@blue.cis.pitt.edu.UUCP> djbpitt+@pitt.edu (David J Birnbaum) writes:
>In article <1992Sep2.152104.13199@ee.eng.ohio-state.edu>
>gan@sample-o.eng.ohio-state.edu (Yin Huang Gan) writes:
>
>>I have been saving lots of articles of the different newsgroups. And I am too 
>>lazy to figure out myself how to write a script for eliminating the headers
>>of the article on the newsgroups (things like Path: , Article:, Keywords ...)
>>with exceptions, Subject: and Date: perhaps. If it's not too much to ask, 
>>could anyone please send me a copy of the script ? Thanks in advance. 
>
>If you're using rn, save with 'w' instead of 's'. It strips the headers
>for you.
>
>--David

Well, if it exists, could someone mail/post the script to the original
poster and me anyway?  I've been saving with 's' for quite some time
now, and as a result have accumulated probably over a thousand articles
with the headers that I'd like to strip...



-- 
-------------------------------------------------------
Nathan Urban                  nurban@tjhsst.vak12ed.edu
Thomas Jefferson High School for Science and Technology
-------------------------------------------------------
Newsgroups: comp.unix.shell
From: fish@daacdev1.stx.com
Subject: in Korn/Bourne how do you double substitute an env var???
Organization: Goddard Space Flight Center
Date: Wed, 26 Aug 1992 18:16:02 GMT

if i had:
foo=bar
barfly=fish
echo ${${foo}fly}	# i want fish as the output but my syntax is bad here

help

			fish
--
John R. Vanderpool                INTERNET: fish@daacdev1.stx.com
NASA/GSFC                         VOX: 301-513-1683                
Hughes/STX Corporation            FAX: 301-513-1608
"arcadian driftwood, gypsy tailwind; they call my home, the land of snow" -jrr
From: friedman@gnu.ai.mit.edu (Noah Friedman)
Newsgroups: comp.unix.shell
Subject: Re: Wierd vi problem under Dynix/ptx
Date: 2 Sep 92 07:41:43 GMT
Organization: Free Software Foundation, 675 Mass Ave. Cambridge, MA 02139
In-reply-to: kim@csc.canberra.edu.au's message of 27 Aug 92 01:37:43 GMT

In article <1992Aug27.013743.1381@csc.canberra.edu.au> kim@csc.canberra.edu.au (Kim Holburn) writes:
>I think if I need to read a manual to use a program then it is basically a
>badly written program.

   I think if I need to read a textbook to understand algebra
then it must be a very poorly developed field of mathematics.
From: kevinl@tisdec.tis.tandy.com
Date: 26 Aug 92 07:53 CDT
Newsgroups: comp.unix.shell
Subject: Re: How can I rm a file with a '&' 
Message-ID: <28300004@tisdec.tis.tandy.com>
Nf-ID: #R:physiol.su.OZ.AU:6563:tisdec.tis.tandy.com:28300004:000:391
Nf-From: tisdec.tis.tandy.com!kevinl    Aug 26 07:53:00 1992


	I'm so sorry I offended you with my attempted help on this file
removal business.  You are obviously superior to me.  I think I'll just
go wallow in self pity, and contemplate the reason for fate dealing me
such an inferior intellect when compared to how smart you think you are.

	By the way, I put in a second post which I tested and works.  If
it's simplicity is beneath you, bend over.

Newsgroups: comp.unix.shell
From: darrell@netcom.com (Darrell Sell)
Subject: C shell nested 'if' problem
Date: Fri, 28 Aug 92 03:39:45 GMT
Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
Followup-To: comp.unix.shell
Distribution: usa
Keywords: csh

I have a csh problem with nested if--else if--else statements.  The 
example below, gives the expected branching behavior, only if the parens
are removed from the first inner if expression.  With the parens
it gets confused if the first if expression is false.

Does anyone have an explanation?  This is not just an exercise to try to
stump the experts, I have a client with a few thousand lines of csh scripts
that I am modifying.  I can probably get around the problem by changing 
one of the if chains into a switch, but I would like to understand what
is going on.

Books like "Unix in a Nutshell" or "The Unix C Shell Field Guide" or the
csh man page don't say anything on the topic.

Thanks. You can respond to this news group or send replies directly to me
at darrell@netcom.com.

=============test script
#! /bin/csh -f
#
if( $1 == 1) then
	echo "first if is true, param = $1"
	if  $2 == "a"   then
		echo "inner if true, alpha = $2" 
  	else if($2 == "b") then 
  		echo "first inner else if true, alpha = $2"
  	else  
		echo "inner else loop, alpah = $2"
  	endif
 else if ($1 == 2) then
 	echo "first outer else if is true, param = $1"
 else if( $1 == 3) then
 	echo "second outer else if is true, param = $1"
 else
 	echo "outer else, param = $1"
endif
exit 0
	

Newsgroups: comp.unix.shell
From: Harald.Eikrem@delab.sintef.no
Subject: Re: Keeping mods AND owners of copied files
Organization: SINTEF DELAB, Trondheim, Norway.
Date: 27 Aug 92 02:21:26

kan9691@bcstec.ca.boeing.com (Ken Niedermeyer) reported:

! Thanks to everyone who emailed solutions AND examples!!!
! Here is what I found out:
! 
! cpio will copy directory hierarchies preserving mods and owners:
! 
!         create the directory to be copied to (newdirectoryname)	
! 	cd to the directory to be copied from
!         find . -depth -print | cpio -pdlm newdirectoryname
! 
! tar will copy directory hierarchies (without going to tape first)
!     preserving mods and owners:
! 
! 	create the directory to be copied to (newdirectoryname)
! 	cd to the directory to be copied from
! 	tar cf - . | (cd newdirectoryname; tar xpfB -)

Also check out GNU `cp -a' if you can, latest version found in
fileutils-3.3, I believe.

  ~~harald E.
From: hlj@posix.COM (Hal Jespersen)
Newsgroups: comp.unix.shell
Subject: Re: file removal problem solved.
Date: 31 Aug 92 23:05:46 GMT
Organization: POSIX Software Group, Redwood City, CA

jerry@incc.com (Jerry Rocteur) writes:
: 
:   IN OTHER WORDS, DO AN ls -i OF THE PROBLEM FILE, STAY WITHIN THAT
:   DIRECTORY, DO A find . -inum nnnn -exec rm {} \; WHERE nnnn IS THE
:   NUMBER DISPLAYED TO THE LEFT OF YOUR FILES NAME, AND THAT IS IT,
:   YOUR PROBLEM FILE IS DELETED...................

This is a nonportable solution that you're espousing.  Neither the POSIX
shell spec nor XPG{3,4} include find -inum.  The SVID does.

I'd be interested to know why the more traditional rm -i ./A* solution
didn't work for the original poster.

Hal
Newsgroups: comp.unix.shell
From: a-douglas@uchicago.edu (Allen Douglas)
Subject: Shell Iteration
Organization: U of C  Law School
Date: Mon, 31 Aug 1992 15:00:05 GMT

Hello,
I need to get the shell or awk to take a large file and pipe segments 
to a temporary file where I can then run some awk or agrep commands 
(on the temporary file.)   The file is a collection of legal cases, 
delimited by "of 38 CASES" I want to awk/agrep the individual cases 
and output to a results file.


The logic is: 

Read in to beginning of first break point (case)-(this output will be discarded)
Start reading the first case until beginning of next case and send text of case to temporary file .
	   Process commands on temp file, output to results file(s.)
Read in text of the next case, until the begining the next+1 case.    (replacing the previous output)

The cases (as in legal case) have delimeters of "of 38 CASES" 


I haven't been able to fathom the syntax, as I am very green programming Unix. 



Newsgroups: comp.unix.shell
From: digdon@ug.cs.dal.ca (Mike Digdon)
Subject: Re: How to empty a file
Organization: Math, Stats & CS, Dalhousie University, Halifax, NS, Canada
Date: Wed, 26 Aug 1992 15:58:39 GMT

In article <17g4kbINN4bm@seven-up.East.Sun.COM> ltaylor@blinky.East.Sun.COM writes:
>
>>> I'd like to empty a log file after extracting what I need from it so that
>>> the next day's data can fill it up a-fresh.  The file must exist after
>>> emptying it.
>
>cp /dev/null <logfile>
>
>/laura

You could also do:

	echo > logfile

-- 
	     Mike Digdon - Vice Prez DSCSS - Dalhousie University
		     digdon@ug.cs.dal.ca  -- Halifax, NS
		 - Real programmers never work nine to five -
Newsgroups: comp.unix.shell
From: dhami@cs.ubc.ca (Mandeep S Dhami)
Subject: > Need Script To Kill Process Using Substring Of Application Name
Summary: from lwall
Keywords: zap, perl
Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
Date: Mon, 31 Aug 92 01:35:46 GMT

From westes@netcom.com:
>
> Does anyone have a script that they could send to me that will take as
> its input some substring and then kill any process you own that has that
> substring in its application name?  So the script would do something
> like:
> 
> 	ps guaxww | grep "some_substring"
> 
> then it would exclude the line that contained the grep command, locate
> the PID of the remaining processes, and kill each one.  Please post the
> script for others to see if its short enough.
> 
I use this perl script (from THE CAMEL BOOK), hope it helps:
-------------------8<----- snip ----->8-------------------------
#!/usr/local/bin/perl

# Usage: zap [-signal] pattern

# Configuration parameters.

$sig = 'TERM';

$BSD = -f '/vmunix';
$pscmd = $BSD ? "ps -auxww" : "ps -ef";

open(TTYIN, "</dev/tty") || die "can't read /dev/tty: $!";
open(TTYOUT, ">/dev/tty") || die "can't write /dev/tty: $!";
select(TTYOUT);
$| = 1;
select(STDOUT);
$SIG{'INT'} = 'cleanup';

if ($#ARGV >= $[ && $ARGV[0] =~ /^-/) {
    if ($ARGV[0] =~ /-(\w+)$/) {
	$sig = $1;
    } else {
	print STDERR "$0: illegal argument $ARGV[0] ignored\n";
    }
    shift;
}

if ($BSD) {
    system "stty cbreak </dev/tty >/dev/tty 2>&1";
}
else {
    system "stty", 'cbreak',
    system "stty", 'eol', '^A';
}

open(PS, "$pscmd|") || die "can't run $pscmd: $!";
$title = <PS>;
print TTYOUT $title;

# Catch any errors with eval.  A bad pattern, for instance.

eval <<'EOF';
while ($cand = <PS>) {
    chop($cand);
    ($user, $pid) = split(' ', $cand);
    next if $pid == $$;
    $found = !@ARGV;
    foreach $pat (@ARGV) {
	$found = 1 if $cand =~ $pat;
    }
    next if (!$found);
    print TTYOUT "$cand? ";
    read(TTYIN, $ans, 1);
    print TTYOUT "\n" if ($ans ne "\n");
    if ($ans =~ /^y/i) { kill $sig, $pid; }
    if ($ans =~ /^q/i) { last; }
}
EOF
&cleanup;

sub cleanup {
    if ($BSD) {
	system "stty -cbreak </dev/tty >/dev/tty 2>&1";
    }
    else {
	system "stty", 'icanon';
	system "stty", 'eol', '^@';
    }
    print "\n";
    exit;
}

# End of file
--
__________________________________________________________________
"I'm very brave generally," he went on in a low voice:
"only to-day I happen to have a headache."
                                      -- Lewis Carroll
From: warnold@gossip.urich.edu (William W. Arnold)
Newsgroups: comp.unix.shell
Subject: Re: tcsh: How to disable printing motd w/o disabling mail check?
Date: 27 Aug 92 14:08:06 GMT
Organization: University of Richmond

In <17dnbeINNq2f@agate.berkeley.edu> forest@soda.berkeley.edu (Forest Edward Wilkinson) writes:
>I'm using tcsh, and would like to disable the printing of /etc/motd
>at login, without getting rid of the "You have {new} mail" messages.

if (`ls -t1 $mail $home/.hushlogin | head -1` == $mail) then
  echo '-----new mail-------'
  touch $home/.hushlogin
endif

-- 
-billy-  warnold@nomad.urich.edu   has8wwa@cabell.vcu.edu
Xref: sparky comp.unix.shell:3759 comp.unix.questions:10637
From: es_macar@rcvie.co.at (Gilles Macario-Rat)
Subject: Re: How to detect login shell in .cshrc ?
Keywords: csh login ps
Reply-To: es_macar@rcvie.co.at
Organization: Alcatel ELIN Research
Date: Wed, 26 Aug 1992 12:23:28 GMT

My login shell is csh on a SunOS 4.1.2 system
rcsw68% uname -a 
SunOS rcsw68 4.1.2 4 sun4c
rcsw68% ps $$
  PID TT STAT  TIME COMMAND
22682 co S     0:04 -csh (csh)
rcsw68% ps
  PID TT STAT  TIME COMMAND
23540 co R     0:00 ps
rcsw68% csh -f
rcsw68% ps $$
  PID TT STAT  TIME COMMAND
23541 co S     0:00 -sh -f (csh)

In the ps man pages:

     ps displays the process ID, under PID; the control  terminal
     (if any), under TT; the cpu time used by the process so far,
     including both user and system time), under TIME; the  state
     of  the  process,  under STAT; and finally, an indication of
     the COMMAND that is running.
	^^^^^^^^^

In the csh man pages:

  Initialization and Termination
     When first started, the C shell normally  performs  commands
     from  the  .cshrc file in your home directory, provided that
     it is readable and you either own it or your real  group  ID
     matches  its  group  ID. If the shell is invoked with a name
     that starts with `-', as when started by login(1), the shell
		     ^^^^^^^
     runs  as  a login shell.  In this case, after executing com-
     mands from the .cshrc file, the shell executes commands from
     the  .login file in your home directory; the same permission
     checks as those for .cshrc are applied to this file.   Typi-
     cally, the .login file contains commands to specify the ter-
     minal type and environment.

In the login man pages:

     login initializes the user and group  IDs  and  the  working
     directory,  then starts a command interpreter shell (usually
     either sh(1) or csh(1)) according to specifications found in
     the file /etc/passwd.  Argument 0 of the command interpreter
			  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     is the name of the command interpreter with a  leading  dash
     (`-') prepended.
    ^^^^^^^^


Could anyone explain what is:

	+ "an indication of the COMMAND that is running"
	+ "Argument 0 of the command interpreter" ?

Is there a way to know whether a shell is a login shell ?
From: WEdmunds@cen.ex.ac.uk (W.Edmunds)
Newsgroups: comp.unix.shell
Subject: comp.unix.shell
Date: 25 Aug 92 15:25:12 GMT
Organization: University of Exeter

I am trying to print a newsboard from a global cshrc file, so that when a
user logs in he will only receive new messages. The newsboard consists of a 
directory with a number of files, each being a separate article. An entry in
/etc/lastlogs is touched on each login. The problem is that there is no
natural break between news files. I also wish news files to be displayed
in order, with the latest article displayed last. I have written a shell
script that is invoked by the cshrc script, but it is really ugly, in that
it uses "find" to stat the files. Surely, there is an easier way of achieving
this in Bourne shell or c-shell. 

Many thanks in advance for any help or pointers, Bill Edmunds.

#!/bin/sh
for FILE in `/bin/ls -tr /usr/mail/motds` ; do
        if /bin/find /usr/mail/motds/$FILE -type f -newer /etc/lastlogs/$USER ; then
                /bin/echo "**************************************************************************\n"
                /bin/cat /usr/mail/motds/$FILE
                /bin/echo ""
        fi
done | more
exit
Newsgroups: comp.unix.shell
From: andy@research.canon.oz.au (Andy Newman)
Subject: Re: How to empty a file
Organization: Canon Information Systems Research Australia
Date: Fri, 28 Aug 1992 01:10:03 GMT

digdon@ug.cs.dal.ca (Mike Digdon) writes:
[....stuff about creating empty files deleted]
>You could also do:
>
>	echo > logfile

That method is shell specfic. If your shell uses /bin/echo (i.e.
Bourne shell) you get a file with a single linefeed character NOT a
zero length file. Csh's built in echo doesn't output anything if there
are no arguments, /bin/echo does.
-- 
Andy Newman (andy@research.canon.oz.au)		"int - God's own type"
Newsgroups: comp.unix.shell
From: mcook@fendahl.dev.cdx.mot.com (Michael Cook)
Subject: Re: Korn shell and file descriptors
Organization: Motorola Codex, Canton, Massachusetts
Date: Wed, 26 Aug 1992 02:02:38 GMT

dave@tetra.co.uk (David Sussman) writes:

>I have an interesting Korn Shell problem.  I have a script containing:

>	echo stream 1 >&1
>	echo stream 2 >&2
>	echo stream 3 >&3
>	echo stream 4 >&4

>Under the Bourne Shell this works ok, but the Korn Shell produces:

>	stream 1
>	stream 2
>	./ksh[3]: 3: bad file unit number
>	./ksh[4]: 4: bad file unit number

>Why?

When you do

	echo stream 3 >&3

the shell does a dup2(3,1) for you, which means close file descriptor 1, and
then make it point at whatever file descriptor 3 is pointing at.  If file
descriptor 3 isn't currently open, dup2 fails.  The Bourne shell was probably
ignoring the failure; ksh tells you.

You can test to see whether file descriptor 3 is open like this:

	(exec>&3) 2>/dev/null || echo "3 is not open"

Michael.