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

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-27-2008 03:37 AM
Need help in Directory Structure murtaza Shell Programming and Scripting 5 03-29-2007 11:14 AM
MV files from one directory structure(multiple level) to other directory structure srmadab UNIX for Advanced & Expert Users 4 09-13-2006 04:01 PM
Copying a Directory Structure to a new structure jhansrod UNIX for Dummies Questions & Answers 8 07-27-2005 06:24 AM
Ram structure Dorian HP-UX 1 11-05-2002 09:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-27-2003
props props is offline
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
  #2 (permalink)  
Old 12-27-2003
jayakhanna jayakhanna is offline
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-19-2004 at 02:49 AM..
  #3 (permalink)  
Old 12-27-2003
props props is offline
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
jayakhanna jayakhanna is offline
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-19-2004 at 02:49 AM..
  #5 (permalink)  
Old 12-27-2003
props props is offline
Registered User
  
 

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

aprecciate your help

Happy New Year
Closed Thread

Bookmarks

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 03:52 PM.


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