Simon - your a gem<br><br>there was a few syntax errors in what I was doing - <br><br>here is the corrected version:<br>note the spaces between the brackets [ EXAMPLE ]<br>and 'test' was removed as its not needed. <br>
<br>now onto my "unexpected end of line"<br>cheers,<br>Ben<br><br> #File Locations!<br>location_Parent=~/Documents/sight_of_sound<br>location_IMG=~/Documents/Sight_of_sound/IMG<br>location_AUD=~/Documents/Sight_of_sound/AUD<br>
<br>if [ -d "$location_Parent" ]<br>then<br>echo "Parent Directory OK"<br>else<br> echo "Error: Parent directory does not exist. Creating directory"<br> mkdir $location_Parent<br>fi<br>
<br>if [ -d "$location_IMG" ]<br> then<br> echo "IMG Directory OK"<br>else<br> echo "Error: IMG directory does not exist. Creating directory"<br> mkdir $location_IMG<br>fi<br><br>if [ -d ""$location_AUD"" ]<br>
then<br> echo "AUD Directory OK"<br>else<br> echo "Error: AUD directory does not exist. Creating directory"<br> mkdir $location_AUD<br>fi<br><br><br><br><br><div class="gmail_quote">2009/6/14 Simon Yuill <span dir="ltr"><<a href="mailto:simon@lipparosa.org">simon@lipparosa.org</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Ben,<br>
<br>
This bit of Python will do the dame job for you, if you can use Python<br>
for your scripts:<br>
<br>
<br>
def validateFilePath(filepath, create=False, isDirectory=False):<br>
"""<br>
Converts C{filepath} to absolute form, expanding the<br>
user if necessary,and tests if it exists. If the<br>
directory, or any sub-directory in the path<br>
does not exist, can optionally create it (off by default).<br>
<br>
Returns validated path. If C{create} is set to false,<br>
and the path does not exist, returns C{None}.<br>
"""<br>
absfilepath = os.path.abspath(os.path.expanduser(filepath))<br>
if filepath[-1] == '/':absfilepath = absfilepath + '/'<br>
if not isDirectory:dirpath = os.path.dirname(absfilepath)<br>
else:dirpath = absfilepath<br>
if os.path.exists(dirpath):return absfilepath<br>
if create:<br>
os.makedirs(dirpath)<br>
return absfilepath<br>
else:return None<br>
<br>
<br>
best wishes<br>
Si<br>
<div><div></div><div class="h5"><br>
<br>
Ben Rush wrote:<br>
> Im trying to check if a series of directory exists and if not create<br>
> them, and am having issues. All the instances of test return with the<br>
> error "test: [-d: unary operator expected" . Searching around I see that<br>
> if the variable is in double quotes its solves the problem - but for<br>
> some reason, not for me. The script still makes the directories if the<br>
> don't exists, however if they DO - it still tries to create them.<br>
><br>
> What noob things am I doing wrong here?<br>
><br>
> This is just one small but of my puzzle - if there is anybody<br>
> knowledgeable in shell scripting that could give me a few hours to in<br>
> the next day or so - I'd be happy to pay for your time.<br>
><br>
> Cheers,<br>
> Ben Rush<br>
><br>
> [code]<br>
> #!/bin/bash<br>
> location_Parent=~/Documents/sight_of_sound<br>
> location_IMG=~/Documents/Sight_of_sound/IMG<br>
> location_AUD=~/Documents/Sight_of_sound/AUD<br>
><br>
> if test [-d "$location_Parent"]<br>
> then<br>
> echo "Parent Directory OK"<br>
> else<br>
> echo "Error: Parent directory does not exist. Creating directory"<br>
> mkdir $location_Parent<br>
> fi<br>
><br>
> if test [-d "$location_IMG"]<br>
> then<br>
> echo "IMG Directory OK"<br>
> else<br>
> echo "Error: IMG directory does not exist. Creating directory"<br>
> mkdir $location_IMG<br>
> fi<br>
><br>
> if test [-d "$location_AUD"]<br>
> then<br>
> echo "AUD Directory OK"<br>
> else<br>
> echo "Error: AUD directory does not exist. Creating directory"<br>
> mkdir $location_AUD<br>
> fi<br>
> [/code]<br>
><br>
><br>
><br>
><br>
</div></div>> ------------------------------------------------------------------------<br>
><br>
> _______________________________________________<br>
> members mailing list<br>
> <a href="mailto:members@electronclub.org">members@electronclub.org</a><br>
> <a href="http://lists.electronclub.org/cgi-bin/mailman/listinfo/members" target="_blank">http://lists.electronclub.org/cgi-bin/mailman/listinfo/members</a><br>
><br>
> Instructions for changing your mailing list settings:<br>
> <a href="http://lists.electronclub.org/emailhowto.html" target="_blank">http://lists.electronclub.org/emailhowto.html</a><br>
<br>
_______________________________________________<br>
members mailing list<br>
<a href="mailto:members@electronclub.org">members@electronclub.org</a><br>
<a href="http://lists.electronclub.org/cgi-bin/mailman/listinfo/members" target="_blank">http://lists.electronclub.org/cgi-bin/mailman/listinfo/members</a><br>
<br>
Instructions for changing your mailing list settings:<br>
<a href="http://lists.electronclub.org/emailhowto.html" target="_blank">http://lists.electronclub.org/emailhowto.html</a><br>
</blockquote></div><br>