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.<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 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. <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>