Linux with Operating System Concepts



Download 5,65 Mb.
Pdf ko'rish
bet98/254
Sana22.07.2022
Hajmi5,65 Mb.
#840170
1   ...   94   95   96   97   98   99   100   101   ...   254
Bog'liq
Linux-with-Operating-System-Concepts-Fox-Richard-CRC-Press-2014

Arithmetic Operators
Meaning
+


, *, /
Addition, subtraction, multiplication, division
**
Exponent (e.g., x**2 is x
2
)
%
Modulo (division retaining the remainder only)
~
Negation of 1’s complement value
<

>

< =

> =

= =

< >
, ! 
=
Relational operators, the last two are available for not equal
a
<<

>>
, &, 

, |
Bit operations (left/right shift, AND, XOR, OR)
&&, ||, !
Logical AND, OR, NOT
=
Assignment
+ =

− =
, * 
=
, / 
=
, % 
=
Reassignment (e.g., x 
=

+
y can be written as x
+
=
y)

=

∧ =
, | 
=

<< =

>> =
Reassignment using &, 

, |, 
<<

>>

Note that we do not use 
<

<=
, and so on in conditional statements. We cover this in Section 7.4.


Shell Scripting

255
• 
let N+=1
• Reassign N to be 1 greater, N is now 3, note that without the “let” statement, N
+
=

is interpreted instead as string concatenation
• 
let Y=$N+1
• Y is 4, the $ in front of N is not needed so this could be let 
Y = N + 1
• 
let Z=Y%N
• Z is 1 (4/3 has a remainder of 1)
• 
Y=$(($Y+1))
• Y is now 5, we can omit the $ before Y
• 
let Y=$((Y << 2))
• Y is now 20. 
<<
is a left shift which results in a number being doubled. The num-
ber 2 in this instruction indicates that the left shift should be done twice. As Y was 
5, the left shift doubles Y to 10 and then 20.
• 
((Y++))
• Y is now 21
• 
((Q––))
• As Q had no value, it is now 

1
• N
=
$N
+
1
• N has the value of 3 
+
1 (literally a 3, a plus, and a 1) because $N
+
1 is treated as a 
string concatenation operation instead of an arithmetic operation
You must specify the arithmetic operations correctly. For instance, a statement like 

=
$((Y 
+
Z*))
will yield an error because the operation is lacking an operand. The spe-
cific error will look like: 

+
Z*: syntax error: operand expected (error 
token is “*”).
You can specify multiple assignment statements on the same line. This is accomplished 
by separating each assignment with a space. For instance, rather than assigning three vari-
ables on separate lines as in

=
1

=
2

=
3
we could do this in one instruction as 

=
1 Y 
=
2 Z 
=
3
.
The Bash interpreter also has a command called 
expr
which performs and returns the 
result of a string or arithmetic operation. This is not part of an assignment statement; instead 


256

Linux with Operating System Concepts
the result is printed to the terminal window. You might use this if you need to see the result 
of a quick computation. Here are some examples. Assume N is 3.
• 
expr $((N+1))
• This returns 4 without changing N
• 
expr $N+1
• This is treated as string concatenation and returns the string 3 
+
1
• 
X=‘expr $((N+1))‘
• The expr command computes and returns 4, which is then stored in X, so X stores 
4 when this instruction concludes
7.3.5 String Operations Using 
expr
The 
expr
command is commonly used with string operations. Three string operations 
are 
substr

index,
and 
length
. The format of the expr statement using a string oper-
ation is
expr 

Download 5,65 Mb.

Do'stlaringiz bilan baham:
1   ...   94   95   96   97   98   99   100   101   ...   254




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish