Skip to content

Instantly share code, notes, and snippets.

@venator85
Created January 26, 2017 10:51
Show Gist options
  • Save venator85/d8552019a20aa947f59fabc735093a91 to your computer and use it in GitHub Desktop.
Save venator85/d8552019a20aa947f59fabc735093a91 to your computer and use it in GitHub Desktop.
fold (hard wrap) in pure bash
fold() {
data="$1"
width="$2"
length=$(echo -n "$data" | wc -c)
while [ $length -gt $width ]
do
echo ${data:0:$width}
data=${data:$width}
length=$(echo -n "$data" | wc -c)
done
echo $data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment