Active Topics

 


Reply
Thread Tools
Posts: 569 | Thanked: 462 times | Joined on Jul 2010 @ USA
#1
Is there some syntax for execution of two commands on one command line, without pressing <enter> between them?

Something along the lines of
Do this | Do that

I am trying to avoid using a shell script, & hoping there is some way to concatenate two commands on one command line.
 
Estel's Avatar
Posts: 5,028 | Thanked: 8,613 times | Joined on Mar 2011
#2
its &&

so:

command1 && command2

But, shell scripts doesn't bite, and sometimes && may not work for You - i.e. in cases, where finishing command1 is required for command2 to function properly. Of course, You may do some command1 && wait 2 && command2, but it's starting to look like too much hassle/ugly code.
__________________
N900's aluminum backcover / body replacement
-
N900's HDMI-Out
-
Camera cover MOD
-
Measure battery's real capacity on-device
-
TrueCrypt 7.1 | ereswap | bnf
-
Hardware's mods research is costly. To support my work, please consider donating. Thank You!
 

The Following 3 Users Say Thank You to Estel For This Useful Post:
jflatt's Avatar
Posts: 534 | Thanked: 723 times | Joined on Oct 2009
#3
otherwise, use a semicolon
 

The Following 4 Users Say Thank You to jflatt For This Useful Post:
sifo's Avatar
Posts: 1,359 | Thanked: 1,292 times | Joined on Oct 2011 @ Tartus.Syria
#4
EsTeL totally right
__________________
[ N900-Crack ] [ The Purge ] [ New Smiles ] [ New icons ] [ ? ]
" Hey ! I've just met you and this is crazy, so install cssu maybe ? "
Please help out keeping Maemo.org alive, and consider donating.
https://www.facebook.com/ZoRk7
 
coredumb's Avatar
Posts: 92 | Thanked: 74 times | Joined on Nov 2008 @ Indonesia
#5
Originally Posted by Estel View Post
its &&

so:

command1 && command2

But, shell scripts doesn't bite, and sometimes && may not work for You - i.e. in cases, where finishing command1 is required for command2 to function properly. Of course, You may do some command1 && wait 2 && command2, but it's starting to look like too much hassle/ugly code.
cmiiw, command2 executed only if command1 finish with exit code 0
 

The Following 3 Users Say Thank You to coredumb For This Useful Post:
Posts: 91 | Thanked: 11 times | Joined on Apr 2012
#6
try command1 ; command2 here command 2 is executed no matter command 1 succesfully executed or not, incase you need this
 

The Following 2 Users Say Thank You to c4rl05 For This Useful Post:
Posts: 1,808 | Thanked: 4,272 times | Joined on Feb 2011 @ Germany
#7
Just for completeness:

$ command1 ; command2
= execute first command1 and then command2, no matter what.

$ command1 && command2
= execute command1 and then command2 only if command1 exits 0 (= success)

$ command1 || command2
= execute command1 and then, if it fails (exit code != 0) execute command2
 

The Following 8 Users Say Thank You to reinob For This Useful Post:
Posts: 2,802 | Thanked: 4,491 times | Joined on Nov 2007
#8
One more:

Code:
$ command1 & command2
launches command1 as a background process, and immediately command2 in the foreground.
 

The Following 5 Users Say Thank You to lma For This Useful Post:
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 11:50.