Results 1 to 3 of 3

Thread: Help in Scripting

  1. #1
    Join Date
    Sep 2012
    Location
    Guntur
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Help in Scripting

    How can we check weather the directory is created or not in shell script???

    i mean if i write

    mkdir dirname

    and if i have to run the script continuously

    is there a way to check weather the directory exists or not???

    can we do that?

  2. #2
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Help in Scripting

    You can either check the exit status of the mkdir command directly

    Code:
    mkdir "$dir" || do something
    or by using the built-in exit status variable $?

    Code:
    mkdir "$dir"
    if [ $? -ne 0 ]; then ...
    or test the directory existence with the -d file test

    Code:
    if [ -d "$dir" ]; then ...
    Just some ideas

  3. #3
    Join Date
    Sep 2012
    Location
    Guntur
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Help in Scripting

    Quote Originally Posted by steeldriver View Post
    You can either check the exit status of the mkdir command directly

    Code:
    mkdir "$dir" || do something
    or by using the built-in exit status variable $?

    Code:
    mkdir "$dir"
    if [ $? -ne 0 ]; then ...
    or test the directory existence with the -d file test

    Code:
    if [ -d "$dir" ]; then ...
    Just some ideas
    Thank you

Bookmarks

Posting Permissions

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