can anyone give a look to this bash script of mine please? I am trying to find the longest line in a file using a bash script so I wrote this.
#!/bin/bash
#Francesco Foschi length of a row in a file
let n=0
let max_length=0
while read row
do
length=$(echo -n $row | wc -c)
if[ ${#length} -gt ${#max_length} ]
then
let max_length=${#length}
fi
echo "$n row is $length charachters long"
echo "$row"
let n=n+1
done < $1
echo "longest line is $max_length charachters long"
exit 0
Every time I try to run the console says that I have a syntax error near the unexpected then token. What am I doing wrong??
BTW running of fedora28