0

I am trying to run the below script.

val = `wc -l /home/validate.bad | awk '{print $1}' | tail -n1`
valCount = `wc -l /home/validation.txt | awk '{print $1}'`
if [ "$val" -gt 1 ] && ["$valCount" -gt 1]
then
    mailx -s "Validation failed" -r [email protected] [email protected]<<-EOF
Hi ,
Validation has failed. Please check.
EOF
elif [ "$valCount" -gt 1 ]
then
    mailx -s "Validation pass" -r [email protected] [email protected]<<-EOF
Hi Team,
Validation success.
EOF
fi

But I am getting this error.

Error:
val: comand not found
valCount: command not found
line 3[: : integer expression expected
1
  • 2
    Assuming this is bash: You have spaces around the assignment operator. Use val= and valCount= respectively. Commented Jul 28, 2016 at 3:20

1 Answer 1

1

You can't have spaces around = :

val = `wc -l /home/validate.bad | awk '{print $1}' | t` # wrong

and should have been

val=`wc -l /home/validate.bad | awk '{print $1}' | t`

or preferrably

val=$(wc -l </home/validate.bad) 
#`..` is legacy , $() supports nesting, one good reason to go for it
# You use awk and tail uselessly 

Also

["$valCount" -gt 1]

should have been

[ "$valCount" -gt 1 ] # mind the spaces for the test constructie
# [spaceSTUFFspace] is the correct form

Sidenote

You may use [ shellcheck ] to check your scripts.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.