Sponsored Content
Full Discussion: if elseif fi
Top Forums Shell Programming and Scripting if elseif fi Post 302485409 by methyl on Wednesday 5th of January 2011 06:50:23 AM
Old 01-05-2011
There were a number of issues (missing "then", orphaned "elif" , wrong answer displayed etc.). In the end it is much easier to use a "case" statement for the options.
For rapid testing I have surrounded this example menu in a do-done loop and removed lots of "exit" statements. There are now no "else" or "elif" statements in the script which makes it much easier to follow.

Code:
while true
do

echo ""
echo "1.FILE PERMISSION"
echo "2.FILE INODE NUMBER"
echo "3.FILE SIZE"
echo "4.FILE OWNER"
echo " Enter what do you want from the option"
read num

case $num in
1)
    echo " Enter filename you want permissions for : "
    read file1
    if [ ! -f $file1 ]
    then
        echo " FILE NOT FOUND"
    fi
    echo " FILE PERMISSIONS for $file1 = `ls -ltr $file1 | awk '{print $1}'` "
    ;;
2)
    echo " Enter filename for which you want INODE NUMBER for : "
    read file1
    if [ ! -f $file1 ]
    then
        echo " FILE NOT FOUND"
    fi
    echo " FILE INODE NUMBER for $file1 = `ls -il $file1 | awk '{print $1}'` "
    ;;
3)
    echo " Enter filename for which you want SIZE  : "
    read file1
    if [ ! -f $file1 ]
    then
        echo " FILE NOT FOUND"
    fi
    echo " FILE SIZE for $file1 = `ls -lad $file1 | awk '{print $5}'` "
    ;;
4)
    echo " Enter filename for which you want OWNER for : "
    read file1
    if [ ! -f $file1 ]
    then
        echo " FILE NOT FOUND"
    fi
    echo " FILE OWNER for $file1 = `ls -lad $file1 | awk '{print $3}'` "
    ;;
*)
    echo "You have not chosen from the list"
    exit 0
    ;;
esac
#
done



@gcvinayak
Please start a new thread in future. Just realised that this is a completely different subject.

Last edited by methyl; 01-05-2011 at 07:57 AM..
This User Gave Thanks to methyl For This Post:
 

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk if elseif syntax error

Below is the code. nawk -F "|" 'FNR==NR{a=$3 OFS $4 OFS $5 OFS $6;next} {\ if ($5 in a)\ {print $1,"ABC",$5,"I",a, $2,$3,$4 OFS OFS OFS OFS OFS OFS OFS OFS $2"-"$3"-"$4} ; \ elseif ($5=="g")\ print $1,"ABC",$5,"I",$5 OFS OFS OFS OFS $2,$3,$4 OFS OFS OFS OFS OFS... (8 Replies)
Discussion started by: pinnacle
8 Replies

2. Shell Programming and Scripting

elseif in csh

I have been using the if statement in csh like this if ( $opt1 == 1 ) then ..... elseif ( $opt2 == 1 ) then ...... endif Seems to work, but got Badly placed ()'s. When I used a space in the elseif, a space between the 'else' and the 'if' it worked (0 Replies)
Discussion started by: kristinu
0 Replies

3. Linux

if elseif fi

Hi all, This is my first post in this forum, can i request you to guide, where i am going wrong with the error below. 34: Syntax error: "fi" unexpected (expecting "then") #!/bin/sh argCount=0 mysql_path=$USER_INSTALL_DIR$ for i in $*; do /A argCount+=1 done if ;then echo... (2 Replies)
Discussion started by: oracle_coorgi
2 Replies

4. UNIX for Dummies Questions & Answers

If Then ElseIf Script - Confusion Around Expression's Syntax

Hello, I am relatively new to UNIX scripting and am learning a lot. I have already tried several searches on this website and have tried various syntax options suggested to no avail. I am obviously not writing the script correctly. I really do appreciate any and all the help. Below is an... (8 Replies)
Discussion started by: dqrgk0
8 Replies

5. Programming

Problem with IF ELSEIF and GOTO statements in FORTRAN

Hi I am reading a book about Fortran 90 and I write the following code, to test my understanding of the first chapter. I have a problem with the last section of the code with deals with an IF, ELSEIF, and GOTO statements. Here is my Code PROGRAM sim ! This code is used to solve two... (3 Replies)
Discussion started by: faizlo
3 Replies

6. AIX

Elseif & for condition in AIX

I'm using the below statements in my script if && then sqlplus sysadm/abcdefgh12@${dbarr} @/u1/scripts/ResetPswd.sql elif then for idx in 0 1 2 3 4 5 6 7 do sqlplus sysadm/abcdefgh12@${dbarr} @/u1/scripts/ResetPswd.sql done else exit fi It give me... (5 Replies)
Discussion started by: Pandee
5 Replies
diff3(1)						      General Commands Manual							  diff3(1)

Name
       diff3 - 3-way differential file comparison

Syntax
       diff3 [-ex3] file1 file2 file3

Description
       The command compares three versions of a file, and publishes the ranges of text that disagree, flagged with the following codes:

	  ====	      all three files differ

	  ====1       file1 is different

	  ====2       file2 is different

	  ====3       file3 is different

       The type of change needed to convert a given range of a given file to some other is indicated in one of these ways:

	  f : n1 a    Text is to be appended after line number n1 in file f, where f = 1, 2, or 3.

	  f : n1 , n2 c
		      Text is to be changed in the range line n1 to line n2.  If n1 = n2, the range may be abbreviated to n1.

       The original contents of the range follows immediately after a c indication.  When the contents of two files are identical, the contents of
       the lower-numbered file is suppressed.

Options
       -3   Produces an editor script containing the changes between file1 and file2 that are to be incorporated into file3.

       -e	   Produces an editor script containing the changes between file2 and file3 that are to be incorporated into file1.

       -x	   Produces an editor script containing the changes among all three files.

Examples
       Under the -e option, publishes a script for the editor that incorporates into file1 all changes between file2 and  file3  -  that  is,  the
       changes	that would normally be flagged ==== and ====3.	Option -x (-3) produces a script to incorporate only changes flagged ==== (====3).
       The following command applies the resulting script to `file1':
       (cat script; echo '1,$p') | ed - file1

Restrictions
       Text lines that consist of a single `.'	defeat -e.

Files
       /tmp/d3?????
       /usr/lib/diff3

See Also
       cmp(1), comm(1), diff(1), dffmk(1), join(1), sccsdiff(1), uniq(1)

																	  diff3(1)
All times are GMT -4. The time now is 12:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy