How do I embed CRLF or other unprintable characters in my shell script?

920 Views Asked by At

My boss came to me with a question about how to embed a CRLF sequence into his shell script (for piping through some sort of netcat or telnet stuff he's doing) in a reasonably portable and robust way.

2

There are 2 best solutions below

2
On

My suggestion for him:

#!/bin/sh
crlf="$(echo xy | tr xy '\r\n')"

... but I'm open to other comments. It's certainly fine with modern versions of GNU tr and bash.

0
On

Assuming POSIX is a good baseline for "portable enough",

printf "\r\n"