Ask Different is a question and answer site for power users of Apple hardware and software. 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 would like to run the following command and pipe stout of both to TextEdit:

pmset -g; echo; pmset -g assertions | open -f -a TextEdit 

This doesn't work, it only executes the latter:


share|improve this question
up vote 11 down vote accepted

Aahhh, bash redirection :-

( pmset -g && echo && pmset -g assertions ) | open -f -a TextEdit

That runs your commands as a single bash command (that's the effect of &&) in a sub-shell (which is what wrapping it in the () does) and redirects the output of the sub-shell into TextEdit for you. You technically don't have to use && instead of ; but the effect of changing it is that if any of the commands fail it will stop the entire chain at that point.

Note: In your example all the commands are being run (as you can prove by just running pmset -g; echo; pmset -g assertions at the command line), it's just that you are applying the pipe to only the last one. That's why it needs to be run in a subshell.

Note: that you could replace the | character with > and send the output to a file if you wish.

share|improve this answer
This little tip has been incredibly helpful. The ins & outs of built in commands/ special characters are scarcely documented. Thank you again. – njboot Dec 22 '14 at 4:28

()'s combine the commands into a single process, concatenating them to stdout:

(pmset -g; echo; pmset -g assertions) | open -f -a TextEdit
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.