problem facing in if -else condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem facing in if -else condition
# 1  
Old 04-23-2010
problem facing in if -else condition

can u plz tell me where is the error

Code:
echo enter the filename to be searched
read fname
if [ -e $fname ] #-d $fname
then
   echo file exists
   if [ -d $fname ]
   then
        echo itsa directory
   elif [ -r $fname ]
   then
      echo its readable
      cat $fname
   else
       echo its not readable
   fi
else
   echo file does not exist
fi

###################################
in fact i want to achieve an inner if condition to be executed when the outer If holds true..

Last edited by Franklin52; 04-23-2010 at 04:28 AM.. Reason: Please use code tags!
# 2  
Old 04-23-2010
How about:
Code:
echo enter the filename to be searched
read fname
if [ -e $fname ] #-d $fname
then
  echo file exists
  if [ -d $fname ]
  then
    echo itsa directory
  elif [ -r $fname ]
    then
      echo its readable
      cat $fname
  else
    echo its not readable
  fi
else
  echo file does not exist
fi

It is advisable to use indentation so it becomes easier to understand the code.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

facing problem using su

Hi, I am able to login using su - or su directly , # prompt is coming, it doesnt ask for password. any normal user on aix system is login using su - or su . Please suggest where to change the configuration direct root login is disabled in /etc/ssh/sshd_config file. (0 Replies)
Discussion started by: manoj.solaris
0 Replies

2. Shell Programming and Scripting

Problem facing in using awk command

Hi., I am not able to replace the string with another string using gsub fn of awk command. My code: awk 'BEGIN gsub(004,IND,004)' p.txt and my i/p file p.txt is of the format: av|004|adkf|Kent,004|s av|005|ssdf|Kd,IT park|s . . . and my desired o/p should be of : (13 Replies)
Discussion started by: av_vinay
13 Replies

3. Shell Programming and Scripting

Facing problem in incrementing the variable

When I did, echo $SHELL in cmd prompt of putty, its displaying /bin/sh And in my shell script., I hav started with., #!/bin/sh and i=1; while ; do . . . i=$; (9 Replies)
Discussion started by: av_vinay
9 Replies

4. Solaris

Facing Problem with metaset in SVM

hi all, i am using solaris 5.10 on sun blade 150 and i am trying to configure diskset in sun volume manager. When i fire the following command, it says some rpc related error. bash-3.00# metaset -s kingston -a -h u15_9 metaset: u15_9: metad client create: RPC: Program not registered how to... (4 Replies)
Discussion started by: kingston
4 Replies

5. Solaris

Facing problem with zone

i am using this way to create zone1 and zone2 bash-2.05b# zonecfg -z zone1 zone1: No such zone configured Use 'create' to begin configuring a new zone. zonecfg:zone1> create zonecfg:zone1> set zonepath=/zone/1 zonecfg:zone1> set autoboot=true zonecfg:zone1> add net zonecfg:zone1:net>... (6 Replies)
Discussion started by: coxmanchester
6 Replies

6. Shell Programming and Scripting

Line space problem facing

Hi, I got a list of file that all got the same standard format. Can anyone teach me how to put the space in all of them?! Input file: >nucleotide1 AAAAAAAAACCCGGG >nucleotide2 GGGGGGCCCCCTTTTA >nucleotide3 GGTACACCACACTCAC >nucleotide4 TTTGGAGAGAGACCCC desired output:... (4 Replies)
Discussion started by: patrick87
4 Replies

7. Programming

facing problem with IBMTriggerMonitor in hp-ux with jdk1.6

Hi, We are facing problem with IBMWebsphereMQ6.0 TriggerMonitor while invoking java appliation in hp-ux with jdk1.6. With other versions of jdk triggermonitor is able to invoke the java application successfully in the same environment. We are facing problems with jdk1.6 only. Following is the... (3 Replies)
Discussion started by: urspradeep330
3 Replies

8. Solaris

please help as i am facing problem with uptime

Hi I am getting the uptime output as follows 12:40am up 4 day(s), 18:29, 2 users, load average: 38.97, 36.54, 34.89 The load average is too high . I have checked the processes , but no process is taking too much cpu time Please help (3 Replies)
Discussion started by: guy009
3 Replies

9. UNIX for Dummies Questions & Answers

facing a problem in redirection

Hi, I am doing this perl script print (@line(1..15)); the lines 1 to 15 get printed... how can i redirect this to file? thanks and regards vivek.s (4 Replies)
Discussion started by: vivekshankar
4 Replies
Login or Register to Ask a Question