How can I make several commands to be executed after a && or a ||?

PleegWat pleegwat at telfort.nl
Fri Feb 17 22:29:59 UTC 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02/17/2012 11:08 PM, Johnny Rosenberg wrote:
> Something like the following, described in some kind of
> self-invented pseudo code:
> 
> If ThisCommand exits successfully { printf("Something"); 
> SomeVariable=3; } DoSomethingElse
> 
> 
> How could I do something similar with bash?
> 
> You know, something like this:
> 
> ThisCommand && ( echo $Something SomeVariable=3) DoSomethingElse
> 
> 
> What's the syntax for this?

What you've written should work; if it doesn't play with the whitespace.

However, shell script also has an if command. This is even usable on
the interactive shell.

if ThisCommand
then
	echo $Something
	SomeVariable=3
fi
DoSomethingElse

PleegWat
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPPtTiAAoJEAM6sLJjDJaMEIcH/19e9a3q1gH87gqFG1vsQK9l
OD2Ec50AD60oCjS9QAYnLxp8VG820PSKfABpaxQ8hZw0Hf+BwT3N+30KLFk64chx
zxMR+V5QBhf8+wZrFGnWVLcbd2n+DiNzh4F88/TK7jjVCC1Q8A5lR8N+WMQaTCLx
BJQZb4mMAHuHdvCm5RgHFjbUvF4PkUIlBBFNiPw/soOq/FWtSIx1CtxHvafEWrsD
jxHfEcRmfi5dsq7BPHTqKkTt3L/rM6MSALfEV9p+IY/tESEEH9JF6Bie+4qThysB
u7g56jkqJvuGvF7WBYF2iGxlne+qLYyAam4WRkMjIHkIpnqjFOa2c+7xl4XVhQM=
=FjsE
-----END PGP SIGNATURE-----




More information about the ubuntu-users mailing list