[ELECTRON] Shell Scripting help? "test: [-d: unary operator expected"

Ben Rush orionrush at gmail.com
Sun Jun 14 13:27:43 UTC 2009


Im trying to check if a series of directory exists and if not create them,
and am having issues. All the instances of test return with the error "test:
[-d: unary operator expected" . Searching around I see that if the variable
is in double quotes its solves the problem - but for some reason, not for
me. The script still makes the directories if the don't exists, however if
they DO - it still tries to create them.

What noob things am I doing wrong here?

This is just one small but of my puzzle - if there is anybody knowledgeable
in shell scripting that could give me a few hours to in the next day or so -
I'd be happy to pay for your time.

Cheers,
Ben Rush

[code]
#!/bin/bash
location_Parent=~/Documents/sight_of_sound
location_IMG=~/Documents/Sight_of_sound/IMG
location_AUD=~/Documents/Sight_of_sound/AUD

if test [-d "$location_Parent"]
then
echo "Parent Directory OK"
else
    echo "Error: Parent directory does not exist. Creating directory"
    mkdir $location_Parent
fi

if test [-d "$location_IMG"]
 then
    echo "IMG Directory OK"
else
    echo "Error: IMG directory does not exist. Creating directory"
    mkdir $location_IMG
fi

if test [-d "$location_AUD"]
then
    echo "AUD Directory OK"
else
    echo "Error: AUD directory does not exist. Creating directory"
    mkdir $location_AUD
fi
[/code]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.electronclub.org/pipermail/members/attachments/20090614/f9e67d86/attachment.htm>


More information about the members mailing list