LINUX programming

Moderators: ITA
Number of threads: 1339
Number of posts: 2924

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
new in UNIX programming..please Posted by taco_bel on 30 Oct 2002 at 2:37 AM
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!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.