Server Fault is a question and answer site for system and network administrators. 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 am performing some interactive testing using HP's QuickTest Professional and Linux. I am connecting via SSH and feeding the BASH script lines directly into the command line.

The problem I'm having is that the script executes as it is entered. I'm attempting to find a way that I can feed the script to the command line, but save execution until the entire script is complete.

Anyone have any experience around doing this? I'll admit, it isn't the ideal way to perform this, but it's what I'm faced with at the moment. Any other suggestions are welcome.


share|improve this question
up vote 2 down vote accepted

If you really can't write a script file to the system, you could wrap your commands in parenthesis:

 ( ls; echo this; echo that; )

same deal, multiline:

echo this
echo that
share|improve this answer
Thanks for all of the answers everyone. I'm still open to more suggestions on how to complete this task, but this answer works perfectly for the current problem. – MHGL Mar 18 '10 at 16:41

You can also wrap your script in curly braces if you don't want it to execute in a subshell:

echo one
echo two

Another way is to pipe an echo into sh or bash:

echo '
echo one
echo two
' | bash

or use eval:

eval '
echo one
echo two


This also works:

bash <<EOF
echo one
echo two
share|improve this answer

cat | ssh '/bin/bash -'

But, if you can ssh, you can just SCP the completed script up anyways? Edit, and if you can't SCP, you can:

cat | ssh 'cat >'

share|improve this answer
2xUUOC: < ssh '' – William Pursell Mar 18 '10 at 18:03

No familiar with "HP's QuickTest Professional", but what stops you from writing it into a file and executing it?

share|improve this answer

I'd look at batch - it does almost exactly what you want.

share|improve this answer

This really depends on what you mean by "not execute until you have given it all the lines". Bash is an interpreted language (not compiled), so no matter which way you slice it, shell will read and execute lines one at a time, each command will generate its own return code independently, regardless of whether you put these commands in subshells or other things.

So what I suspect you are really asking is:

(a) is there a way for you to gather all the output in one screen area without interruption

(b) is there a way for you to have to only press the "Enter" key once to have all the commands run in sequence

If you join each command line separated by a semicolon ';' then this has the same effect as running them on different lines. So string them all together on one line and press "Enter" once at the end. You may do this manually by typing, or you may process your shell script through a tool (like sed or tr) to replace End-of-Line characters with semicolons, and then feed the result into ssh. On your local host, run the following:

cat | tr "\n" ';' | ssh [remote host]

Note that this does not create an interactive shell on the remote host, it only runs the commands from the script and then returns control to your local host.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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