#!/bin/bash set -e dev=/dev/usb/lp0 text="$1" size="$(printf '%s' "$text" | wc -c)" size="$(expr "$size" + 3)" size="$(printf '%04x' "$size" | sed -e 's/\(..\)\(..\)/\\x\2\\x\1/g')" # Store data printf '\x1D(k' > $dev printf "$size" > $dev printf '\x31\x50\x30' > $dev printf '%s' "$text" > $dev # Print data printf '\x1D(k' > $dev printf '\x03\0\x31\x51\x30' > $dev # Cut paper printf '\x1DVA\0' > $dev