question in shell script

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions question in shell script
# 1  
Old 08-29-2011
question in shell script

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:


Write a Bourne shell script which:
Has one command line argument.
If the command line argument is a directory then the script should output the number of files in the directory.
If the command line argument is an ordinary file then the script should output whether or not the file has execute permission for the file owner.
If the command line argument is neither a file or directory then the script should output an appropriate error message.
If no command line argument is supplied then the script should output an appropriate error message.

2. Relevant commands, code, scripts, algorithms:



3. The attempts at a solution (include all code and scripts):



4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Curtin university, sedney, Australia, 101.

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
# 2  
Old 08-29-2011
I notice that the section with your attempts is alarmingly blank. Did you try anything yet? Or are you hoping that someone here will do your work for you?

Aside from that, as far as I know it's spelled Sydney. And what 101 course are you taking?
# 3  
Old 08-29-2011
Quote:
Originally Posted by pludi
I notice that the section with your attempts is alarmingly blank. Did you try anything yet? Or are you hoping that someone here will do your work for you?

Aside from that, as far as I know it's spelled Sydney. And what 101 course are you taking?
sorry you are right ! its Sydney

i tried and im stuck with last two points.

this is my work :

Code:
#!/bin/sh

echo " Command line argument is :" $1

if [ -d $1 ]
then
    echo " The number of files in the directory is ` ls -l | wc -l` "
else
    echo " It is not a dirctory "
fi

if [ -f $1 ]
then
    echo " The execute permission for the file owner is ` ls -l  $1`"
else
    echo " There is no execute permission "
fi

# 4  
Old 08-29-2011
First of all, I don't think your script behaves as required, at least I don't see a requirement to tell the user that the argument isn't a directory, or doesn't have the executable bit set.

Try to get the logical flow down for the script first, and jot down some pseudo-code, eg
Code:
if argument given
  if directory
    count files
    exit
  else if file
    if executable
      say so
    else
      say not executable
  else
    argument is something else
else
  say error

For the tests, test (shorthand: [ ... ]) has some very valuable operators to check for files, directories, executables, and if a string has zero length.

BTW, with your method of counting you'll have a one-off error. Compare the output of ls -l | wc -l and ls | wc -l. I'll leave it to you to find the source of that error Smilie
# 5  
Old 08-30-2011
I notice that you posted the identical question on LQ.org. Here is a reply from there.
Quote:
... There is no pass mark or degree waiting for any of us for passing YOUR assignment.

Also, if you read a little closer through the replies you will see that solution suggestions have been given, plus I am sure things haven't changed too much since I studied that the teacher / lecturer is asking you to do something
that has not been covered.
# 6  
Old 08-31-2011
Quote:
Originally Posted by pludi
First of all, I don't think your script behaves as required, at least I don't see a requirement to tell the user that the argument isn't a directory, or doesn't have the executable bit set.

Try to get the logical flow down for the script first, and jot down some pseudo-code, eg
Code:
if argument given
  if directory
    count files
    exit
  else if file
    if executable
      say so
    else
      say not executable
  else
    argument is something else
else
  say error

For the tests, test (shorthand: [ ... ]) has some very valuable operators to check for files, directories, executables, and if a string has zero length.

BTW, with your method of counting you'll have a one-off error. Compare the output of ls -l | wc -l and ls | wc -l. I'll leave it to you to find the source of that error Smilie
Thank you for helping me

the time is up for submission !
i will try to revise again. i hope i can share my knowledge with you soon ...

Quote:
Originally Posted by ananthap
I notice that you posted the identical question on LQ.org. Here is a reply from there.
yes, i was trying to gather info as much as i can
Thank you ...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script question

As per code it is getting matched. not sure why it assigning to cols=0. Any inputs please. Input : passed is shell.sh c tablename. if ; then cols=1 table=$2 else cols=0 table=$1 fi (1 Reply)
Discussion started by: ramkumar15
1 Replies

2. Shell Programming and Scripting

Shell script question

Hi all, can you plz check whether the below code is correct & some inputs. I need to read the below file and process it. input : /home/ibm/var.txt urgent not urgent not needed. #!/usr/bin/ksh VAR=/home/ibm/var.txt if ] then (7 Replies)
Discussion started by: ramkumar15
7 Replies

3. Homework & Coursework Questions

question on shell script

hiiiiiiiiiiiii,,I found an error on my following script but couldnt find it!!! Can you please help me as soon as possible?! echo "enter a number " read n i=0 first=0 second=1 result=0 prime="true" echo –n " $first $second " while do result=`expr $first + $second` first=$second... (10 Replies)
Discussion started by: moonlips
10 Replies

4. Homework & Coursework Questions

Question on shell script

Hiiiiiiiiiiiii all, Please i want your help fast, the teacher gave us this assignment can u help me to write it? this is the question: Write a shell script to point all prime numbers from the fibonacci series of integer N? using Red hat Os Thanks all and waiting for ur answers... (1 Reply)
Discussion started by: moonlips
1 Replies

5. Shell Programming and Scripting

shell script question

I have script as following.. server_status= some command | grep "Total error: 0" if ; then echo " Server $(hostname) is Down" >>Result fi else echo " Server is OK on $(hostname)" >>Result the if command seems to be not working properly for some... (13 Replies)
Discussion started by: s_linux
13 Replies

6. Shell Programming and Scripting

shell script question

Hi, The contents of my file is below: Name,Location,Degree,Gender,Awards Robert,Philadelphia,Accounting,Male,5 Jane,Chicago,Business,Female,2 Allan,New York,Engineering,Male,6 Tom,Detroit,Computer Science,Male,10 Nancy,Milwaukee,Engineering,Female,4 I want to add a "ID" in the 1st line... (2 Replies)
Discussion started by: xinoo
2 Replies

7. Shell Programming and Scripting

Shell Script question

Hello Experts, I am new at this and need some help. I am looking for a delete command that allows me after I grep for the hostname to delete all the lines between two characters. for example I want to delete the first line all the way up to the } character host test019 { hardware ethernet... (10 Replies)
Discussion started by: ryanique
10 Replies

8. UNIX for Dummies Questions & Answers

Linux Shell Question: how to print the shell script name ?

Suppose I have a script named "sc.sh" in the script how to print out its name "sc.sh"? (3 Replies)
Discussion started by: meili100
3 Replies

9. Shell Programming and Scripting

Shell script question

Hello, i am doing a project for school and i cannot figure out whats wrong with my 2 programs they dont seem to work at all. the first program is called isprime and naturally it checks to see if hte number is prime or not here is my code: #!/usr/bin/bash num=$1 echo you typed if ... (2 Replies)
Discussion started by: jbou1087
2 Replies

10. Shell Programming and Scripting

shell script question

I am using ksh. There is a report having amounts in the following format, 34343.67- 2343.45 23434.89- I want to sum up all the amounts. For this I first need to find out if there is a minus sign at the end and prefix it before summing up. How to achieve this? I thought of using an... (2 Replies)
Discussion started by: tselvanin
2 Replies
Login or Register to Ask a Question