If then Else statement in shell script

Hi,

I am having a shell Script which i need to modify. I am new to shell scripting , needs help. The Logic which needs to be incorporated is as follows :-

The script need to check the length of first Line in a data fine and of the length of the file is > 130 then validated the input parameter in the shell script for e,g :-

variable = $ Length -1|Data file| wc - ?

if $ variable > 133 + 'R'
Abort
if $ variable < 180 + 'D'
Walk forward

Note : 'R' and 'D' are paramater passed to shell scipt at runtime. The Variable should check the length of datafile first and then compare it with the input parameters , If input Parameter is 'R' then it should check the legth of datafile and if it finds the legth > 133 the prog should abort and press a message that "the user shold pass 'D' instaed of 'R' and vice versa.

something like above.

Regards

Milind

Sounds like homework.... :slight_smile:

Assuming that "variable" contains an intenger value and an "option" variable contains either R or D.

if [ "$option" = 'R' -a "$variable" -gt 133 ]; then
   # you said abort, so I assume exit here
    echo 'You should pass D instead, because value > 133' >&2
    exit 1
fi
if [ "$option" = 'D' -a "$variable" -lt 180 ]; then
   echo 'You should pass R instead because value < 180' >&2
   exit 1
fi

How to define $variable in script?

$variable should measure length of first record in a Datafile.

Thanks