![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 | ||
|
|
|
|||
|
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
JK added code tags for readability --oombera Last edited by oombera; 02-18-2004 at 10:49 PM. |
|
|||
|
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
JK added code tags for readability --oombera Last edited by oombera; 02-18-2004 at 10:49 PM. |