The UNIX and Linux Forums  

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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search attributes in one structure using the values from another structure dhanamurthy High Level Programming 3 03-26-2008 11:37 PM
Need help in Directory Structure murtaza Shell Programming and Scripting 5 03-29-2007 08:14 AM
MV files from one directory structure(multiple level) to other directory structure srmadab UNIX for Advanced & Expert Users 4 09-13-2006 01:01 PM
Copying a Directory Structure to a new structure jhansrod UNIX for Dummies Questions & Answers 8 07-27-2005 03:24 AM
Ram structure Dorian HP-UX 1 11-05-2002 05:48 AM

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-27-2003
Registered User
 

Join Date: Oct 2003
Location: uk
Posts: 15
if then else structure

echo name the file that you want to read
read answer

if [ $# = 0 ]
then
echo you must enter a file name

fi
cat $answer


im trying to catch the error if user forget to enter the name of the file

anyone can help me ?
thanks
Forum Sponsor
  #2 (permalink)  
Old 12-27-2003
Registered User
 

Join Date: Dec 2003
Location: India
Posts: 50
Code:
echo "Enter answer"
read answer

echo $answer | od -b

if [ "$answer" = "" ]
then
        echo "You must enter a file name"
        exit 1
else
        cat $answer
fi
Regards
JK

added code tags for readability --oombera

Last edited by oombera; 02-18-2004 at 10:49 PM.
  #3 (permalink)  
Old 12-27-2003
Registered User
 

Join Date: Oct 2003
Location: uk
Posts: 15
% sh mmm
Enter answer
fileX
0000000 146 151 154 145 130 012
0000006
cat: cannot open fileX



jayakhanna this is what comes up if you run the code
  #4 (permalink)  
Old 12-27-2003
Registered User
 

Join Date: Dec 2003
Location: India
Posts: 50
I am really sorry I was just checking the octal value for \n.
Okay any how the program should be like this

echo "Enter answer"
read answer

if [ "$answer" = "" ]
then
echo "You must enter a file name"
exit 1
else
cat $answer
fi


Well from your mail I think your concern is that you want to check whether the particular file exists or not, Am i right. If so then
use the below code after *read answer* in the above code
Code:
if [ ! -s $answer ]
then
     echo "The file does not exist"
     exit 1
fi
Regards
JK

added code tags for readability --oombera

Last edited by oombera; 02-18-2004 at 10:49 PM.
  #5 (permalink)  
Old 12-27-2003
Registered User
 

Join Date: Oct 2003
Location: uk
Posts: 15
no worries now the program works fine!!!

aprecciate your help

Happy New Year
Google UNIX.COM
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0