0

This is kind of a 2 part question and you'll understand why when done reading. To start, I was trying to figure how to cause an "enter" action inputted into standard output so that the script can inject a password into standard input (yes, I'm aware there are ssh-keys. It's more for the challenge of doing it). First, how do you do an "enter" in a bash script? I feel like \n is different in a small way. And, what does \e do. It's not documented in man bash.

To help clarify, I'm attempting to perform an "enter" functionality that would start an openssh-client connection.

#!/bin/bash

ssh miphix@foo.bar [options] [interpreted enter command/token]
&& sleep 5s
&& echo "supersecretpassword" [interpreted enter command/token]

quickly followed by what other dreamy piles of fairy dust i can come up with.

  • 2
    You don't "input" into STDOUT (it's standard output), so what do you mean exactly? And what are you trying to do more specifically? \e introduces a generic escape sequence which is interpreted by the terminal and not by the shell. – kos Dec 2 '15 at 2:49
  • I think maybe you need to use a semicolon ; just a guess. – mchid Dec 2 '15 at 4:10
  • mchid it appears that there is no definition in man for ';' as a reserved function. Is this a SHell reservation for "sudo" scripts? – Miphix Dec 2 '15 at 11:46
1

Try this:

echo -ne '\n' | <command>

or just literally send to take advantage of implicit newline of echo:

echo | <command>
  • I think you're trying to say <command> | echo – Miphix Dec 2 '15 at 11:48
  • No, I mean echo | <command> – Tung Tran Dec 2 '15 at 13:32
  • Ok, not to be combative or inflammatory. Would you be so kind as to either expand on the logic, or link to an example? >echo "secretpassword" | ssh miphix@foo.bar – Miphix Dec 2 '15 at 17:56

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.