Find the answer to your Linux question:
Results 1 to 5 of 5
i am currently in a Linux class and i am stuck on this script what it needs to do is 1st the command with no parameters should respond with my ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    2

    basic scripting help

    i am currently in a Linux class and i am stuck on this script what it needs to do is
    1st the command with no parameters should respond with my name. 2nd command -d with display the number of directories in the current dir.
    3rd command -f with display the number of files in teh current directory.
    4th for EX command -d "dirname" will display the number of dirs in the spectific dir, "dirname.
    5th command -f dirname will display the number of files is dirname directory.
    6th error if what is entered doesn't match any of the above

    here is what i have so far(doesn't work)
    Code:
    #!/bin/sh
    
    if [ $1 = '-f'];
    then ls | wc -l;
    else if [$1 = '-d'];
    then  ls -d */| wc -l;
    fi
    fi
    Last edited by 74kumi; 10-20-2008 at 07:36 PM. Reason: code changed

  2. #2
    Trusted Penguin Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,392
    While it's not strictly a homework question, it's still academic learning. If someone here answers this for you, you learn nothing. That doesn't help you and it doesn't help us, that's why homework questions are against the rules.

    Maybe others will be able to make suggestions to guide you to the right solution, buy I'm pretty sure that the answers to these questions will be in your course notes.

    As you've been honest enough to tell us that you're in Linux class, I'll not lock this thread, but I will ask others not just dive in with a complete answer, you just need a few pointers.
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    Linux Newbie
    Join Date
    Jan 2008
    Location
    UK
    Posts
    211
    Hi,
    As a starter if you have not done this already.
    Write a seperate script for each of the operations that you wish to do,
    once they all work start putting them together.
    This although labourious can be a good way to see how things fit together.
    And do not worry about how long a script is, you can refine it later after it all works.

    wowbag1

  4. #4
    Just Joined!
    Join Date
    Oct 2008
    Posts
    2
    it keeps giving me " ./ux12asmt4: [: missing `]' " what is it asking for ?

  5. #5
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    It can't find the closing bracket. Probably, because you are missing a blank space in front of it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...