A Unix shell command alternative to echo

I'm trying to output string literals to a file. So far I've been trying to use the echo command, but unfortunately I've discovered it's impossible to output '-n', '-e' or '-E' (at least not without much complicating the code). Is there any alternative command that I can use to output a literal string?

It's preferable if the command is available in the remote machines I'm connecting to – I'm trying to update files on the remote side.

Of course, I can simply pass the data from the client side, but if I do I need to reconnect to the SSH server after each command.

The workaround I'm using:

echo alabama | ssh server dd of=/tmp/alabama conv=fsync
echo china | ssh server dd of=/tmp/china conv=fsync

What I want to do:

(echo 'echo alamaba | dd of=/tmp/alabama conv=fsync'
echo 'echo china | dd of=/tmp/china conv=fsync') | ssh server /bin/sh

I'm passing random strings from a random program, and I want to ensure that the latter form can work with the strings '-e' and '-n' and '-N'


Solution 1:

Use printf:

printf '%s\n' "-n"