#!/bin/sh i=128 a="sed" echo="`which echo`" while [ $i -lt 256 ]; do oct="`printf %03o $i`" # dash's internal echo doesn't know -e char="`"$echo" -e \\\\$oct`" a="$a -e 's/$char/\\\\\\\\$oct/g'" i=`expr $i + 1` done # bash and dash differ here: bash creates double backslashes, dash single echo "$a"|sed 's/\\\\\\\\/\\\\/g'