The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-26-2008
nokicky nokicky is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 1
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 (permalink)  
Old 11-26-2008
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,944
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.
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0