You can use Replace Commands to wrap the preliminary redirection of the output, and then use the Offset Parameter Extension to limit the number of characters as follows:
#!/bin/bash limit=20 out=$(echo "this line has more than twenty characters in it") echo ${out::limit} > /path/to/file
Proof of concept
$ limit=20 $ out=$(echo "this line has more than twenty characters in it"). $ echo ${out::limit} this line has more t
source share