Bourne Shell People.. what am I doing wrong

Discussion in 'OT Technology' started by cunninglinguist, Oct 28, 2003.

  1. cunninglinguist

    cunninglinguist RAEPERQUICKING

    Joined:
    Oct 5, 2001
    Messages:
    28,932
    Likes Received:
    58
    Location:
    NYC
    I'm using the Bourne shell to write a CGI script. It's supposed to ask the user for input (their userID) and give them a listing of all the files in their directory. I did all that, but we have both undergrad and grad students in this class, and there's a different directory structure (only difference is that instead of the ugrad directory, it goes to grad. I put in an if statement to test to see whether a ugrad directory existed, and if not, then make student="grad" and eventually print the grad directory. Unfortunately, this if statement does nothing. I don't get any listing.

    Here is what I have

    student="ugrad"
    #if [ -d "/homedir/$student/$fchar/$userid" ]
    #then
    #else
    #student="grad"
    #fi

    It's commented out for now, since I can't get it to work, but I was wondering if I was using the correct syntax or if my logic is flawed somewhere. Right now, it works fine for undergrad dir (I tested with my ID) and if I changed the student variable to "grad" it would work for grad students. When I uncomment the previous lines, I don't get any listing whatsoever.


    Any thoughts?
     
  2. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    You can't have an empty then clause. Why not check for the negative? if [ ! -d "..."]
     
  3. cunninglinguist

    cunninglinguist RAEPERQUICKING

    Joined:
    Oct 5, 2001
    Messages:
    28,932
    Likes Received:
    58
    Location:
    NYC
    Thanks :bigthumb:, I tried that but for some reason it wasnt working. Guess thats what I get for doing it a 4 in the morning.
     

Share This Page