Don't Ask Me to Do Your Homework

If you're dishonest enough to ask me to do your homework for you, at least try not to be too blatant about it. And if you're clueless enough to turn in what you're given, you deserve to fail the course.

Date: Wed, 13 Nov 2002 12:41:18 +0000
From: "S.P.Xxxx" <Xxxxxxxx@xxxxxxxxx.xx.xx>
To: <arensb@xxxxxxx.xxx>
Subject: 

Dear Andrew
i am trying to find out how to use unix. can you help?
With this problem:-

) Write a script that provides a file, "MyFiles", that contains a list of all 
the files in the current directory and displays on the screen the number of 
files present in the current directory.

B) Write a script that moves all the files that end in ".txt" from the current 
directory to another (target) directory. The target directory should be 
identified via a parameter passed to the script. This script should also 
produce a text file ("filesCopied") that lists all files that have been moved.

C) Write a script that  reads in ten numbers (either one at a time during 
script execution or as parameters) and prints to the screen the sum of these 
numbers (hint - you may need to check out the "read" command).

D) Alter the previous script to allow it to work for arbitrary lists of 
numbers.

I found your webpage very informative, unfortunately i am still unable to find 
a solution to the above.

thanks for your time,

Xxxxx Xxxx ( my real name ).

Date: Wed, 13 Nov 2002 09:37:58 -0500
From: Andrew Arensburger <xxxxxx@xxxxxxx.xxx>
To: "S.P.Xxxx" <Xxxxxxxx@xxxxxxxxx.xx.xx>
Cc: arensb@xxxxxxx.xxx
Subject: Re: your mail

On Wed, Nov 13, 2002 at 12:41:18PM +0000, S.P.Xxxx wrote:
> i am trying to find out how to use unix. can you help?

	Sure. I haven't read any introductory Unix books in a while,
but I'm partial to O'Reilly books. You can probably find them at your
local technical bookstore. I know they have "Unix in a Nutshell", and
probably have at least one book that has more of a tutorial section.

> With this problem:-
> 
> ) Write a script that provides a file, "MyFiles", that contains a list of all 
> the files in the current directory and displays on the screen the number of 
> files present in the current directory.

	How about this:

	#!/bin/sh
	exec > /dev/tty 2>&1 3>-	# Print to screen
	here=`pwd`
	find / -print | while read filename; do
		case `dirname $filename`
			$here/*)
				if [ -f $filename ]; then
					/bin/ls $filename | awk '{ print $1 }' | tee `echo ZlSvyrf | tr 'a-zA-Z' 'n-za-mN-ZA-M'`
				fi
				;;
			*)	# Ignore it
				;;
		esac
	done
	perl -nae '++$^G END{$_=$^G;print}'

> B) Write a script that moves all the files that end in ".txt" from the current 
> directory to another (target) directory. The target directory should be 
> identified via a parameter passed to the script. This script should also 
> produce a text file ("filesCopied") that lists all files that have been moved.

	Here you go (reformatted for readability):

	#!/bin/sh
	exec 3>`echo hbcfedgabfi | tr 'a-i' 'pilCseofd'`
	t='$'`expr 7 - \( 2 \* 3 \)`
	eval t2=$t
	cat >r <<grep
	echo $1 1>&3
	while read line <$1; do echo $line>$2; done
	grep
	chmod +x r
	find * \( -type d -prune \) -o -name '*.txt' -print -exec ./r {} $t2 \;

> C) Write a script that  reads in ten numbers (either one at a time during 
> script execution or as parameters) and prints to the screen the sum of these 
> numbers (hint - you may need to check out the "read" command).
> 
> D) Alter the previous script to allow it to work for arbitrary lists of 
> numbers.

	Actually, it's best to plan this sort of extensibility right
from the start:

	#!/bin/sh
	set -udba -pdbapasswd
	mysqladmin $* create numbers
	mysql $* numbers<<whereis
	create table ints (
		cut int(10) default 0 not null
	);
	whereis
	while read line; do
		echo $line
	done > read.c <<printf
	#include <stdio.h>
	void da(int c, char **v){ int i; for (i = 0;
		i < c;      i++){ printf("%s\n", v[i])}}
	int  di(int c, int   *v){ static char b[512]; while
		(fgets(b, 512, stdin)
	){ printf("%" "s" "\n", b); }}
	main(int c, char *v[]) { if (c>1) da(c,v);
		else di(6, NULL);
	printf
	cc -o read read.c
	(PATH=. read) | sed 's/\(.*\)/insert into ints values (\1);/' > foo
	mysql < foo
	rm foo
	mysql $* <<read.c
	select count(*) from ints;
	read.c
	shift; shift		# Restore

-- 
Andrew Arensburger                      This message *does* represent the
arensb@xxxxxxx.xxx                      views of ooblick.com
       On the Net, everyone knows you're an idiot. Except you.

Date: Wed, 13 Nov 2002 14:57:01 +0000
From: "S.P.Xxxx" <Xxxxxxxx@xxxxxxxxx.xx.xx>
To: Andrew Arensburger <arensb@xxxxxxx.xxx>

Andrew,
Thanks for that, i may get this assignment in on time after all!

Xxxxx Xxxx