#!/bin/bash
#Variable to store total word count
words=$(wc $1 | awk '{print $2}')
count=$(grep -c "$2" "$1")
echo "Word Count:" $words
echo "Instance count of "$2": "$count
percentage=$(expr $count / $words)
echo $percentage
My machine is running on Windows 10, this is my code, the script takes two arguments - a text file and a word.
words
stores the total number of words from the text file,
while count
stores the instances of the word parameter in the text file.
echo $words
returns 4
and echo $count
returns 1
so why do I get the error: expr: non-integer argument