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

903 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 answers

2
Jim Dennis 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
tripleee On

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

printf "\r\n"