Sponsored Content
Full Discussion: if elseif fi
Top Forums Shell Programming and Scripting if elseif fi Post 302485276 by gcvinayak on Tuesday 4th of January 2011 07:34:51 PM
Old 01-04-2011
Hi Below script is throwing an exception elfi not correct at line no 21.

Can you please have a look at script and advice what is wrong in below script?
Code:
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
if [ $num -eq 1 ]
echo " Enter filename you want permissions for : "
read file1
if [ -f $file1 ]
then
echo " FILE PERMISSIONS for $file1 = `ls -ltr $file1 | awk '{print $1}'` "
exit 0
else
echo " FILE NOT FOUND"
exit 1
fi
elif [ $num -eq 2 ]
echo " Enter filename for which you want INODE NUMBER for : "
read file1
if [ -f $file1 ]
then
echo " FILE INODE NUMBER for $file1 = `ls -il $file1 | awk '{print $1}'` "
exit 0
else
echo " FILE NOT FOUND"
exit 2
fi
elif [ $num -eq 3 ]
echo " Enter filename for which you want SIZE  : "
read file1
if [ -f $file1 ]
then
echo " FILE INODE NUMBER for $file1 = `ls -ltr $file1 | awk '{print $5}'` "
exit 0
else
echo " FILE NOT FOUND"
exit 3
fi
elif [ $num -eq 4 ]
echo " Enter filename for which you want OWNER for : "
read file1
if [ -f $file1 ]
then
echo " FILE OWNER for $file1 = `ls -l $file1 | awk '{print $9}'` "
exit 0
else
echo " FILE NOT FOUND"
echo 4
fi
else
echo "YOu have not chosen from the list"
exit 0
fi


Last edited by Franklin52; 01-05-2011 at 03:54 AM.. Reason: Please use code tags and indent your code.
 

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
if(n)							       Tcl Built-In Commands							     if(n)

__________________________________________________________________________________________________________________________________________________

NAME
if - Execute scripts conditionally SYNOPSIS
if expr1 ?then? body1 elseif expr2 ?then? body2 elseif ... ?else? ?bodyN? _________________________________________________________________ DESCRIPTION
The if command evaluates expr1 as an expression (in the same way that expr evaluates its argument). The value of the expression must be a boolean (a numeric value, where 0 is false and anything is true, or a string value such as true or yes for true and false or no for false); if it is true then body1 is executed by passing it to the Tcl interpreter. Otherwise expr2 is evaluated as an expression and if it is true then body2 is executed, and so on. If none of the expressions evaluates to true then bodyN is executed. The then and else arguments are optional "noise words" to make the command easier to read. There may be any number of elseif clauses, including zero. BodyN may also be omitted as long as else is omitted too. The return value from the command is the result of the body script that was executed, or an empty string if none of the expressions was non-zero and there was no bodyN. EXAMPLES
A simple conditional: if {$vbl == 1} { puts "vbl is one" } With an else-clause: if {$vbl == 1} { puts "vbl is one" } else { puts "vbl is not one" } With an elseif-clause too: if {$vbl == 1} { puts "vbl is one" } elseif {$vbl == 2} { puts "vbl is two" } else { puts "vbl is not one or two" } Remember, expressions can be multi-line, but in that case it can be a good idea to use the optional then keyword for clarity: if { $vbl == 1 || $vbl == 2 || $vbl == 3 } then { puts "vbl is one, two or three" } SEE ALSO
expr(n), for(n), foreach(n) KEYWORDS
boolean, conditional, else, false, if, true Tcl if(n)
All times are GMT -4. The time now is 02:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy