Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

new in UNIX programming..please

hi,
i'm new in learning UNIX. i have been spend over 8 hours to do this program, i still get something wrong with my program.
//////////////////////////////////////////////////////////////////
Here is the question:

Write a C-shell script to:


1) save the names of all directories you have in your account to a file dirlist.
2) print the name of your home directory .
3) print the total number of directories you have in your account.
4) print the names of all your directories in your account.
5) for each directory print the directory name, print separately how
many files it has, how many directories it has.
(i.e. print the number of files as one number, print the number of directories
as another number ).
6) print the total number of files you have in your account.
///////////////// //////////////////////////
Hint:
Part 3) The answer is:


I have 10 directories in my account.
(your current directory is also counted)


Part 4) The answer can be :
The directories are:


.
april
lab
lab/test
lab/sun
news
news/mag
news/old
www
www/src

Part 5) You can print answer in the format:


Inside directory . there are:
1 files, 4 directories


Inside directory april there are:
2 files, 0 directories


Inside directory lab there are:
1 files, 2 directories


Inside directory lab/sun there are:
1 files, 0 directories


Inside directory lab/test there are:
2 files, 0 directories


Inside directory news there are:
0 files, 2 directories


Inside directory news/mag there are:
1 files, 0 directories


Inside directory news/old there are:
2 files, 0 directories


Inside directory www there are:
1 files, 1 directories


Inside directory www/src there are:
1 files, 0 directories


Part 6) You can print the answer as:


In my account the total number of files is: 12

/////////////////////////////////////////////////////////////
Here is my home directory tree:
a andrew dirlist sheng taco
a1 bell homework shing temp

./andrew:
andrew1 andrew2 log

./andrew/andrew1:

./andrew/andrew2:

./sheng:
log3 sheng1

./sheng/sheng1:
nothing

./shing:
log1 shing1

./shing/shing1:

./taco:
log2 taco1

./taco/taco1:
chiu hao
/////////////////////////////////////////////////////////////
Here is my program:(it is really ugly but i did my best.)

#!/bin/csh

echo " "

echo "This is my directory list:"
ls -R | fgrep "." | tee dirlist
echo " "

echo "My home directory is called: `whoami`"
echo " "

set num = `wc -l dirlist`
echo "I have $num[1] directories in my account."
echo " "

ls -F > temp
@ i = 1
foreach (`more temp`)
echo "in the directory $filed[i] i have: "
set d =`ls -F $file[i] | fgrep "*" | wc -l`
echo "$d[1] files."
set f =`ls -F $file[i] | fgrep "." | wc -l`
echo "$f[1] directories."
@ i++
end

set x = `ls -FR * | fgrep "*" | wc -l`
echo "There are $x files in my account."

result:

This is my directory list:
.:
./andrew:
./andrew/andrew1:
./andrew/andrew2:
./sheng:
./sheng/sheng1:
./shing:
./shing/shing1:
./taco:
./taco/taco1:

My home directory is called: sheng

I have 10 directories in my account.

foreach: Invalid variable

when i run the program. question 1 to 4 and question 5 are looks o.k.
but i couldn't solve the question 5.
please Help!

Comments

  • Andre YoungAndre Young USAMember Posts: 0

    _________ ( http://forcoder.org ) free ebooks and video tutorials about [ JavaScript Visual Basic Ruby C++ Visual Basic .NET Swift Assembly C# PHP Scratch Java C R Go MATLAB PL/SQL Python Objective-C Perl Delphi Erlang D Scheme VBScript FoxPro Scala ABAP Crystal ML Fortran Bash Clojure Hack Awk Alice Lisp Transact-SQL Ada SAS Kotlin Logo Julia F# Prolog Lua LabVIEW COBOL Rust Dart Apex ] ______

Sign In or Register to comment.