WEBVTT

00:01.530 --> 00:04.080
Arithmetic expansions in Shell.

00:04.110 --> 00:11.160
The shell allows arithmetic to be performed by an expansion, so this allows us to use the shell prompt

00:11.160 --> 00:12.480
as a calculator.

00:12.480 --> 00:21.000
So, for example, let's do this echo, and now we're going to do here braces, oops, braces here.

00:21.000 --> 00:24.420
And for example, two plus two.

00:24.750 --> 00:27.600
And as you can see here, we got an four.

00:27.720 --> 00:33.300
So arithmetic, exemptions, expansions, you can be used like this, for example.

00:33.300 --> 00:37.020
You will firstly, let's actually use our grommet.

00:37.770 --> 00:43.290
So you will use the expansion, the dollar sign.

00:43.290 --> 00:51.030
And after that, two braces here and you write your expression here expression.

00:55.520 --> 00:56.510
Here.

00:56.510 --> 01:01.040
Now use two curly braces again.

01:01.040 --> 01:03.260
And after that, that's it.

01:03.260 --> 01:09.050
So, of course, don't forget to write your echo command before then.

01:09.050 --> 01:13.820
So we here we have the just an empty space.

01:13.820 --> 01:20.840
So where expression is an arithmetic expression consisting of values and arithmetic operators.

01:20.840 --> 01:30.290
So arithmetic expression expansion supports only integers, whole numbers, no decimals, but can perform

01:30.290 --> 01:32.510
quite a number of different operations.

01:32.510 --> 01:41.390
So for example, it can be used for addition for subtraction, for multiplication, for division.

01:41.870 --> 01:50.240
But remember, since expansion supports only integer arithmetic, the result is going to be always,

01:50.360 --> 01:51.890
always.

01:53.300 --> 01:54.320
Integer.

01:54.350 --> 01:56.300
Integer.

01:56.330 --> 01:57.170
Output.

02:00.510 --> 02:07.230
And it also supports modulo which is which simply means reminder.

02:07.230 --> 02:12.030
And we also have exponentiation, which is two here.

02:12.030 --> 02:16.920
So we also have an exponentiation here.

02:17.720 --> 02:20.330
So spaces are not significant in arithmetic.

02:20.330 --> 02:23.690
Operations and expressions can be nested.

02:23.720 --> 02:27.690
For example, here, let's do another example like this.

02:27.710 --> 02:30.440
So for example, let's write Echo.

02:31.860 --> 02:32.220
Here.

02:35.800 --> 02:38.440
So we will write the nested expression right here.

02:39.270 --> 02:43.140
And after that you call braces again after dollar sign.

02:44.160 --> 02:46.950
And now five multiplication two.

02:47.490 --> 02:49.050
Not this isn't a multiplication.

02:49.050 --> 02:50.910
Actually, it's exponentiation.

02:50.910 --> 02:55.080
And after that we will use that three.

02:55.260 --> 02:57.290
And here, let's see the results here.

02:57.300 --> 02:59.340
So single parentheses.

02:59.340 --> 03:00.720
This is our results here.

03:00.720 --> 03:06.990
So a single parentheses may be used to group a multiple subexpressions.

03:06.990 --> 03:13.770
With this technique, you can rewrite the previous example and get the same result using the single

03:13.770 --> 03:16.110
expression instead of instead of two.

03:26.500 --> 03:29.500
And we can also write the strings and mix it together.

03:29.500 --> 03:33.160
So Echo, for example, five divided.

03:34.900 --> 03:38.620
Divided by two equals.

03:39.490 --> 03:42.870
And after that, we will enter our division here.

03:42.880 --> 03:52.450
So five divided by two and here and as you can see here, five divided by two equals two.

03:52.810 --> 03:57.460
Yeah, that's actually not a Yeah, that's actually true.

03:57.460 --> 04:03.720
But and I said earlier that this expressions in echo.

04:05.670 --> 04:11.610
Supports only integer arithmetic and the result is going to be integers.
