Home Dashboard Directory Help
Search

Implement the && and || operators that bash has by antize


Status: 

Active


9
2
Sign in
to vote
Type: Suggestion
ID: 778798
Opened: 2/7/2013 4:31:39 PM
Access Restriction: Public
0
Workaround(s)
view

Description

Discussion about this at stackoverflow - http://stackoverflow.com/questions/563600/can-i-get-to-work-in-powershell

Jeffery Snover said to request it here so here I am :D

Here is a description of what they do -- http://www.gnu.org/software/bash/manual/bashref.html#Lists

An AND list has the form
         command1 && command2

command2 is executed if, and only if, command1 returns an exit status of zero.

An OR list has the form
         command1 || command2

command2 is executed if, and only if, command1 returns a non-zero exit status.
Details
Sign in to post a comment.
Posted by Christian Rondeau on 6/5/2014 at 6:18 PM
I wanted to add that even though I still support that when the first command fails, the second should not be executed (i.e. using &&) I just learned we can use ";" to split commands on a single line, e.g.:

cls; my-command

I though I'd let people who wander here know :)
Posted by Christian Rondeau on 6/5/2014 at 6:12 PM
A very typical and common example is when you want to run a command several times, and to make your life easier, to clean the screen between each run. You'd use:

cls && my-command

I understand we can build scripts for this, or maybe there are solutions for this specific case, but the point is in our day-to-day to be able to do multiple commands at once.

Another example could be:

git fetch origin && grunt

Thanks for your consideration.
Sign in to post a workaround.