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

With cmd.exe's interpreter this is easy:

echo testline > .\test.txt && c:\windows\system32\notepad.exe .\test.txt

What is the equivelent to this with bash?

For instance, vim doesn't execute when I run the following:

 ./check_nrpe -H -c CheckEventLog -a MaxWarn=1 MaxCrit=1 file='Security' filter=out filter+eventType==auditFailure filter+generated=\<10m filter+eventID==534 filter+message=substr:'mbrown' descriptions > test1.csv && vim test1.csv

Does it have to do with the double redirector?

share|improve this question

closed as not a real question by Zoredache, andol, mbrownnyc, MikeyB, MDMarra Nov 15 '11 at 19:40

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Have you tried doing the same in bash? – andol Aug 31 '11 at 19:21
If you replaced notepad.exe with vi or some other editor, and fixed the slashes, then that command should run as written. – Zoredache Aug 31 '11 at 19:23
yes... corrected original question – mbrownnyc Aug 31 '11 at 19:23
up vote 3 down vote accepted

&& works with short circuiting and second command will execute only if first command is correct. You can try using ; to separate two commands if it is ok for second command to execute unconditionally.

share|improve this answer
will they execute concurrently or sequentially when using the ; ? – mbrownnyc Aug 31 '11 at 19:57
the clue was in the answer. Read and understand before asking a question that has already been answered. – goo Aug 31 '11 at 21:11
The ; separator will cause the commands to execute sequentially. If you want the second command to start without waiting for the first to finish, try using & instead. – Slartibartfast Sep 1 '11 at 4:30

Use the && separator. Just as cmd.exe.

sudo apt-get update && sudo apt-get dist-upgrade
share|improve this answer
Sorry forgot to ad relative paths :'( – mbrownnyc Aug 31 '11 at 19:26
Just ran your amend and it worked perfectly - results.csv got written and vim opened it. – growse Aug 31 '11 at 19:38

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