[mdlug] Difference between ; and &&

Aaron Kulkis akulkis00 at gmail.com
Thu May 10 03:09:16 EDT 2012


Mat Enders wrote:
> Hello all,
> 
> When stringing commands together at the command line I always use the
> semicolon ;  I however see && used frequently and was wondering what
> the difference was.
> 
> For example what is the difference between these commands:
> 
> apt-get update;apt-get dist-upgrade
> and
> apt-get update && apt-get dist-upgrade
> 


there are three constructs here:

(A) command1 ;  command2
(B) command3 && command4
(C) command5 || command6

(A) is shorthand for this:

command1
command2

# Command2 executes in all circumstances.


(B) is shorthand for

if [ command3 ]
then
     command4
fi

# command2 executes only if command1 returns an exit-code of 0

(c)is shorthand for

if [ ! command5 ]
then
       command6
fi

# command2 executes only if command5 returns an exit-code other than 0




More information about the mdlug mailing list