Not getting expected result

Hi Experts,

I have written the below script but its not working as per expectation.
My requirement is if this condition [[ $missing_count -gt 0 ]] is satisfied
then only check for this condition [[ $parm==5 ]] if this also satisfied check for the condition [[ $val -eq $cnt ]].

 
 vi p_values.ksh
path="/db/ora/files"
mode=1
b_days=10
mins=120
freq=15
ksh p_test.ksh $path  $mode $b_days $mins $freq
  
 vi p_test.ksh
path=$1
mode=$2
b_days=$3
mins=$4
freq=$5
missing_count=9
param=$#
echo "param $param"
if [[ $missing_count -gt 0 ]]; then
echo "missing_count condition executed"
    printf "some missing file\n" >> list.txt
    if [[ $parm==5 ]]; then
 echo "param condition executed"
        cnt=`cat list.txt | wc -l`
        val=`expr $mins / $freq`
        if [[ $val -eq  $cnt ]]; then
       echo "frequency check  executed"
        fi
    else
 echo "final missing"
     exit 0
 fi 
fi
 
Execution 1: I have passed 5 parameters.
ksh p_values.ksh
param 5
missing_count condition executed
param condition executed
 
 Execution 2: I have passed 4 parameters.
ksh p_values.ksh
param 4
missing_count condition executed
param condition executed
expr: syntax error
 

Why if [[ $parm==5 ]]; then this condition is still satisfying even I passed 4 parameters .
Could you pleas help me.

Thanks in advance.

couple of things:

if [ $parm -eq 5 ]; then
and
cnt=`wc -l < list.txt`

Hi,

Thanks a lot for your prompt response.
However it's giving expected output.

I have executed with 4 and 5 parameters. Both the cases I got the same output.

 
 ksh p_values.ksh
param 4
missing_count condition executed
final missing
 
ksh p_values.ksh
param 5
missing_count condition executed
final missing

 

this condition is not satisfying in both the cases.

if [[ $parm -eq 5 ]]; then
 echo "param condition executed"
        cnt=`wc -l < list.txt`

Thanks.

without going too much into the code.... shouldn't
if [ $parm -eq 5 ]; then
be
if [ $param -eq 5 ]; then ?
run the script with tracing enabled: set -x and see what happens...

Hi.

Given the indented code on file z6:

path=$1
mode=$2
b_days=$3
mins=$4
freq=$5
missing_count=9
param=$#
echo "param $param"
if [[ $missing_count -gt 0 ]]; then
  echo "missing_count condition executed"
  printf "some missing file\n" >> list.txt
  if [[ $parm==5 ]]; then
    echo "param condition executed"
    cnt=`cat list.txt | wc -l`
    val=`expr $mins / $freq`
    if [[ $val -eq  $cnt ]]; then
      echo "frequency check  executed"
    fi
  else
    echo "final missing"
    exit 0
  fi
fi

the command shellcheck z6 produces:

In z6 line 2:
mode=$2
^-- SC2034: mode appears unused. Verify it or export it.


In z6 line 3:
b_days=$3
^-- SC2034: b_days appears unused. Verify it or export it.


In z6 line 12:
  if [[ $parm==5 ]]; then
        ^-- SC2077: You need spaces around the comparison operator.


In z6 line 14:
    cnt=`cat list.txt | wc -l`
        ^-- SC2006: Use $(..) instead of deprecated `..`
             ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.                                                                    


In z6 line 15:
    val=`expr $mins / $freq`
        ^-- SC2006: Use $(..) instead of deprecated `..`
         ^-- SC2003: expr is antiquated. Consider rewriting this using $((..)), ${} or [[ ]].                                                                   
              ^-- SC2086: Double quote to prevent globbing and word splitting.
                      ^-- SC2086: Double quote to prevent globbing and word splitting. 

Some details for utility shellcheck:

shellcheck      analyse shell scripts (man)
Path    : /usr/bin/shellcheck
Version : ShellCheck - shell script analysis tool
Type    : ELF 64-bit LSB executable, x86-64, version 1 (SYSV ...)
Help    : probably available with -h
Repo    : Debian 8.7 (jessie) 
Home    : http://hackage.haskell.org/package/ShellCheck

On a system like:

OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution        : Debian 8.7 (jessie) 

And note advice from vgersh99 about set -x

Best wishes ... cheers, drl

Hi All,

Thanks a lot for your suggestions.

Regards,
Nalu