[mdlug] Difference between ; and &&
John Wiersba
jrw32982 at yahoo.com
Thu May 10 13:28:48 EDT 2012
Good, except for the [ command ] part. This is correct (and similarly for command5 & 6):
# command4 executes only if command3 returns an exit status of 0
if command3
then
command4
fi
# command6 executes only if command5 returns an exit status other than 0
if ! command5
then
command6
fi
Date: Thu, 10 May 2012 03:09:16 -0400
>From: Aaron Kulkis <akulkis00 at gmail.com>
>Subject: Re: [mdlug] Difference between ; and &&
>To: MDLUG's Main discussion list <mdlug at mdlug.org>
>Message-ID: <4FAB699C.3070709 at gmail.com>
>Content-Type: text/plain; charset=ISO-8859-1
>
>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