Birmingham mumbai



Download 15,21 Mb.
Pdf ko'rish
bet200/482
Sana13.01.2022
Hajmi15,21 Mb.
#355107
1   ...   196   197   198   199   200   201   202   203   ...   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)

[
 148 
]
Understanding variables
Bash is more than just a 
shell. You could argue that it is very similar to a complete 
programming language, and you wouldn't be wrong. Bash is a scripting engine (we 
will get into scripting later) and there are many debates as to what distinguishes a 
scripting language from a programming language, and that line becomes more and 
more blurred as new languages come out. As with any scripting language, Bash 
supports variables. The concept of variables is very simple in Bash, but I figured I'd 
give it its own (relatively short) section to make sure you understand the basics. You 
can set a variable with a command such as the following:
myvar='Hello world!'
When Bash encounters an equal sign after a string, it assumes you're creating a 
variable. Here, we're creating a variable named 
myvar
 and setting it equal to 
Hello 
world!
 Whenever we refer to a variable, though, we need to specifically clarify to 
Bash that we're requesting a variable, and we do that by prefixing it with a dollar 
symbol (
$
). Consider this command:
echo $myvar
If you've set the variable as I have, executing that command will print 
Hello world!
 
to 
stdout
. The 
echo
 command is very useful for printing the contents of variables. 
The key thing to remember here is that when you 
set
 a variable, you don't include the 
$
 symbol, but you do when you retrieve it. Also, keep in mind that there's no space 
on either side of the equals sign.
Variables work in other aspects of the shell as well, not just with 
echo
. Consider this:
mydir="/etc"
ls $mydir
You will see variations of variable name formats as you work with 
various Linux servers. For example, you may see variable names 
in all caps, camel case (
MyVar
), as well as other variations. These 
variations are all valid, and depending on the background of the 
individual creating them (developers, administrators, and so on), 
you may see different forms of variable naming.


Chapter 6

Download 15,21 Mb.

Do'stlaringiz bilan baham:
1   ...   196   197   198   199   200   201   202   203   ...   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