Hi there. I need some help, to see where I am going wrong with this scripting. I have 3 questions which I have to do and have got a bit into it but am stuck. I was wondering if anyone could tell me why the scripts I have dont work, and perhaps tell me how I could change them to make them do so? Anyway here goes:
Quote:
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.
|
Code:
#!/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}'
Quote:
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.
|
Code:
#!/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 \;
Quote:
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).
Alter the previous script to allow it to work for arbitrary lists of
numbers.
|
Code:
#!/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
If anyone can help then please reply
Thanks
Jimmy