7

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'

14

Use printf:

printf '%s\n' "-n"
0

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.