I am having some issues with local variables after exiting a loop. The variable max ends up with the value 0, despite the code below:
max
max=0 cat
Here's a one liner in awk.
$ awk 'length>t{t=length}END{print t}' file 6