Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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'

share|improve this question
up vote 10 down vote accepted

Use printf:

printf '%s\n' "-n"
share|improve this answer

For your particular example, you can use bash here strings (see man). Instead of this:

echo alamaba | dd of=/tmp/alabama conv=fsync

you can do this:

dd of=/tmp/alabama conv=fsync <<< alabama

E.g. try this:

dd of="-e abc -N def" conv=fsync <<< "-e abc -N def"
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .