Unix Homework Help Needed

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Unix Homework Help Needed
# 1  
Old 04-21-2012
Unix Homework Help Needed

Code:
#!/bin/sh

#Buddy Gibbons
#COP3353 - Assignment 4
#4/21/12

file=$1
directories=0
files=0
rfiles=0
xfiles=0
wfiles=0

if [ $# -ne  1 ]
   then
        echo "Usage: assignment4.sh <directory_name>"
exit
fi


if [ ! -d $file ]
then
        echo "$file: is not a directory"
exit
fi
        

for filename in $file/*
     do
        if [ -r $filename ];
            then 
             rfiles = `expr $rfiles + 1`   
        fi

        if [ -x $filename ]
           then
                xfiles = `expr $xfiles + 1`
        fi
 if [ -w $filename ] 
           then  
                wfiles = `expr $wfiles + 1`
        fi

        if [ -d $filename ]
           then
                directories = `expr $directories + 1`
        fi
        if [ -f $filename ] 
           then  
                files = `expr $files + 1`  
        fi
done
        
echo "Total number of directories: $directories"
echo "Total number of files: $files"
echo "Total number of readable items: $rfiles"
echo "Total number of writable items: $wfiles"
echo "Total number of executable items: $xfiles"

********************************************************
my output is just a whole bunch of this:

Code:
assignment4.sh: line 32: rfiles: command not found
assignment4.sh: line 37: xfiles: command not found
assignment4.sh: line 42: wfiles: command not found
assignment4.sh: line 47: directories: command not found
assignment4.sh: line 32: rfiles: command not found
assignment4.sh: line 37: xfiles: command not found
assignment4.sh: line 42: wfiles: command not found
assignment4.sh: line 52: files: command not found
assignment4.sh: line 32: rfiles: command not found
assignment4.sh: line 42: wfiles: command not found
assignment4.sh: line 52: files: command not found
assignment4.sh: line 32: rfiles: command not found
assignment4.sh: line 42: wfiles: command not found
assignment4.sh: line 52: files: command not found
assignment4.sh: line 32: rfiles: command not found
assignment4.sh: line 37: xfiles: command not found
assignment4.sh: line 42: wfiles: command not found
assignment4.sh: line 52: files: command not found
assignment4.sh: line 32: rfiles: command not found
assignment4.sh: line 42: wfiles: command not found
assignment4.sh: line 52: files: command not found



------------------

Can you please alter the code to make it correct and then re-post the entire thing?

------------------


Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
I can't get it to work properly.


2. Relevant commands, code, scripts, algorithms:



3. The attempts at a solution (include all code and scripts):
I tried for hours...


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
UNC, Chapel Hill (NC), USA, Professor David Plaisted, COMP 524: Programming Language Concepts ( it's not letting me post the URL because I don't have 5 posts )

Last edited by Scott; 04-21-2012 at 08:01 PM.. Reason: Code tags
# 2  
Old 04-21-2012
Start by removing spaces from both sides of =

i.e.
Code:
X = `blah`

Becomes
Code:
X=`blah`

Shell is picky about spacing! X=1 means 'assign "1"to X'. X = 1 means 'run something called "X" with arguments "=" and "1"'.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Linux / UNIX (Homework)

My task is to modify the command line cat -n /etc/fstab | grep and after grep, filter to only show line 7. I can't use sed awk or any other command, only grep (1 Reply)
Discussion started by: taurus1992
1 Replies

2. Homework & Coursework Questions

Unix Homework Help needed

1 Petras Pavardenis 1980 5 08 Linas Bajoriunas 1970 10 3 Saulius Matikaitis 1982 2 5 Mindaugas Stulgis 1990 7 6 Rimas Nasickis 1964 10 7 ... (1 Reply)
Discussion started by: vaidastf
1 Replies

3. Homework & Coursework Questions

Sort function -- My First Unix Homework!

1. The problem statement, all variables and given/known data: To sort a data 2. Relevant commands, code, scripts, algorithms: The data provided is saved in dummy.txt and provided in LIBSVM format, but I think this information is redundant.. +1 1:2 2:4 4:3.2 -1 2:2.1 2:2.1 ... (4 Replies)
Discussion started by: eeweepoh
4 Replies

4. Shell Programming and Scripting

Unix Scripting Question (Homework)

Hello im currently taking up Operating Systems and we're on unix ryt now. we have to make a script and here are the requirements.. can someone please help me. I would reli appreciate it.. because i dont reli know how to make scripts yet. Name of script : parkingcharge.sh Create a script that... (1 Reply)
Discussion started by: pitdark
1 Replies

5. Shell Programming and Scripting

Linux unix help (homework, closed)

i have to do this but i am confused, Create a file containing the bash functions which perform the following tasks. Clearly label each function. Print out and turn in this file. 1.Write a function which displays the current date, time, username, and current directory. ... (1 Reply)
Discussion started by: CRAZYLITTLELOU
1 Replies

6. Shell Programming and Scripting

Help Needed in Unix Script

Hi, I have multiple servers and each server hosts multiple databases. Now i have requirement as below 1) Create a file in any server which will hold all the database name. 2) Write a shell script that will read the file and connect to each and every database. and log out of it one by... (2 Replies)
Discussion started by: amritansur
2 Replies

7. UNIX for Dummies Questions & Answers

Help needed in Basic UNIX

hi friends, How to obtain list of groups we r a member of and redirect it to a file. how to append the details of current OS to a file. how to append the estimated file space to a file. how to append the details of users loged on along wth their current activity into a file. Thank you...I'm... (3 Replies)
Discussion started by: bobby36
3 Replies

8. Shell Programming and Scripting

unix manual needed :)

hi guys... am new 2 dis unix world... am in need of a unix manual... cud sum1 pls post sum links 2 download it?>?>? :confused: Danks in advance... ;) ;) ;) (1 Reply)
Discussion started by: sundar_shankar
1 Replies

9. UNIX for Dummies Questions & Answers

Unix help needed !!

friends i wanted to now whehter there exists a book as a solution to the questions posted in exercies of the Design of Unix Operating system by Maurice J Bach !..its really urgent !! (1 Reply)
Discussion started by: darshaan
1 Replies

10. UNIX for Dummies Questions & Answers

Unix help needed!

I have a few questions about Unix. Can you please help! 1.How do I create an alias that greps the password file for my username and returns my password file entry? Once I get the alias to work I want to be able to let a friend use it .So that he can use the alias to locate his password entry... (1 Reply)
Discussion started by: JJJ
1 Replies
Login or Register to Ask a Question