Linux Quick shell scripting question

Discussion in 'Software' started by simon w, 16 Feb 2004.

  1. simon w

    simon w What's a Dremel?

    Joined:
    3 Nov 2003
    Posts:
    1,302
    Likes Received:
    0
    How can I determine if a directory (which is passed to the script as a parameter) exists?

    For example, if I run
    Code:
    myScript test
    or
    Code:
    myScript /home/simon/test
    it should echo either true or false.
     
  2. Hargle

    Hargle What's a Dremel?

    Joined:
    13 Oct 2001
    Posts:
    404
    Likes Received:
    1
    This should do it, but I'm in a hurry so don't be surprised if it doesn't ;)

    Code:
    if [ -d $1  ]
      then
        echo true
    else
        echo false
    fi
    Cheers.
     
  3. simon w

    simon w What's a Dremel?

    Joined:
    3 Nov 2003
    Posts:
    1,302
    Likes Received:
    0
    That did the trick, thanks :thumb:
     
Tags:

Share This Page