Birmingham mumbai



Download 15,21 Mb.
Pdf ko'rish
bet207/482
Sana13.01.2022
Hajmi15,21 Mb.
#355107
1   ...   203   204   205   206   207   208   209   210   ...   482
Bog'liq
Mastering Ubuntu Server Gain expertise in the art of deploying, configuring, managing, and troubleshooting Ubuntu Server by Jay LaCroix (z-lib.org)

[
 153 
]
Bash, like any scripting language, supports branching and the 
If Statement
 is one 
way of doing that. Here, it's checking for the existence of the 
apache2
 binary. The 
-f
 option here specifies that we're looking for a file. We can change this to 
-d
 to 
check for the existence of a directory instead. The exclamation mark is an inverse. It 
basically means we're checking if something is 
not
 present. If we wanted to check if 
something 
is
 present, we would omit the exclamation mark. Basically, we're setting 
up the script to do nothing if Apache is already installed. In this case, inside the 
brackets we are just executing a shell command, and then the result is checked. The 
commands sandwiched inside the 
if
 statement are simply installing packages.
Finally, we close out our 
if
 statement with the word 
if
 backward (
fi
). If you forgot 
to do this, the script will fail.
With regard to the concept of 
if
 statements, we can compare values as well. 
Consider the following example:
#!/bin/bash
myvar=1
if [ $myvar -eq 1]; then
    echo "The variable equals 1"
fi
With this script, we're merely checking the contents of a variable, and taking action if 
it equals a certain number. Notice we didn't use quotation marks when creating the 
variable, since we just set a number (integer) here. We would've only used quotation 
marks if we wanted to set the variable value to a string. We can also take action if the 
if
 statement doesn't match:
#!/bin/bash
myvar=10
if [ $myvar -eq 1]; then 
    echo "The variable equals 1" 
else 
    echo "The variable doesn't equal 1" 
fi 
This was a silly example, I know, but it works as far as illustrating how to create an 
if
/
else
 logic block in Bash. The 
if
 statement checks to see whether the variable was 
equal to 
1
. It isn't, so the 
else
 block executes instead.


Boosting Your Command-line Efficiency

Download 15,21 Mb.

Do'stlaringiz bilan baham:
1   ...   203   204   205   206   207   208   209   210   ...   482




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