if [ -d != doesn't work

Discussion in 'Programming/Scripts' started by alexus, Jan 8, 2007.

  1. alexus

    alexus New Member

    # if [ -d != ~/.ssh/ ] ; then echo mkdir ~/.ssh/ ; fi
    mkdir /root/.ssh/
    # ls -ld ~/.ssh/
    drwxr-xr-x 2 root root 4096 Jan 5 12:19 /root/.ssh/
    #

    how come this doesn't work?
     
  2. martinfst

    martinfst Member Moderator

    Because ~ refers to your real user id (the userid you logged on with) and not root ?
     
  3. alexus

    alexus New Member

    i logged in as root
     
  4. martinfst

    martinfst Member Moderator

    Looks like '[' and 'test' are not similar: Use:
    Code:
    if test ! -d ~/.ssh/  ; then echo mkdir ~/.ssh/ ; fi
    -d check if a directory exists. You cannot do '-d !='
     
  5. alexus

    alexus New Member

    then what does "test" here means?
     
  6. martinfst

    martinfst Member Moderator

    'test' is the equivalent command for '['. In this case it replaces the []. Do
    Code:
    man test
    on your server and you'll see all the options.
     
  7. falko

    falko Super Moderator Howtoforge Staff

  8. alexus

    alexus New Member

    thank you :)
     

Share This Page