help!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers help!
# 1  
Old 11-26-2008
help!

#!/bin/sh

echo -n "enter path of directory > ";
read DIRECTORY

echo -n "enter name and path of file 1 > ";
read FILE1

echo -n "enter name and path of file 2 > ";
read FILE2



if [ "$DIRECTORY" -a "$FILE1" -a "$FILE2"]
then
echo "all paths have been entered"
else
echo "not all paths have been entered"
fi


if [ -d $DIRECTORY]
then
echo "$DIRECTORY ok"
else
echo "$DIRECTORY not ok"
fi


if [ -f $FILE1]
then
echo "$FILE1 ok"
else
echo "$FILE1 not ok"
fi

if [ -f $FILE2]
then
echo "$FILE2 ok"
else
echo "$FILE2 not ok"
fi

why doesn't this work?!?!?
i'm using bourne shell and just want the user to enter and directory and two paths and the script to say whether they exist or not. thanks in advanced!
# 2  
Old 11-26-2008
code tags for code. they make it readable.
Code:
#!/bin/sh
 
echo -n "enter path of directory > ";
read DIRECTORY
 
echo -n "enter name and path of file 1 > ";
read FILE1
 
echo -n "enter name and path of file 2 > ";
read FILE2
 
 
 
if [ "$DIRECTORY" -a "$FILE1" -a "$FILE2"]
then 
    echo "all paths have been entered"
else
    echo "not all paths have been entered"
fi
 
if [ -d "$DIRECTORY" ]
then
    echo "$DIRECTORY ok"
else
    echo "$DIRECTORY not ok"
fi
 
 
if [ -f "$FILE1" ]
then 
    echo "$FILE1 ok"
else
    echo "$FILE1 not ok"
fi
 
if [ -f "$FILE2" ]
then 
    echo "$FILE2 ok"
else
    echo "$FILE2 not ok"
fi

Quote:
why doesn't this work?!?!?
I think you forgot some spaces. if [ -f $FILE] is a syntax error, if [ -f $FILE ] is not. Also, I added some quotes(highlighted for clarity) in places you'll likely need them in order to deal with filenames containing spaces.
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question