Linux with Operating System Concepts



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

Frank Zappa
, the quote marks are required because of the space 
between Frank and Zappa
• 
NAME 
=
Frank Zappa
• An error arises because of the space, the Bash interpreter thinks that Zappa is a 
command, which does not exist
• 
NAME 
=
FrankZappa
• No quote marks are required here because there is no space, so in fact the literal 
value is really one string of 10 characters

NAME 
=
ls *
• An error should arise as Bash tries to execute *, which is replaced by all of the 
entries in the current directory. If all of the entries in the directory are executable 
programs, this will result in all of these programs executing!
• 

=
1.2345
• X stores 1.2345, but the value is a string, not a number
The instruction 
X

1
would yield the error 
Fatal server error: Unrecognized 
option: 
=
.
Unlike the error messages shown in Section 7.2, we do not even get a line 
number informing us of where the error arose!
The assignment statement can copy the value of one variable into another. To retrieve 
the value stored in a variable, you must precede the variable name with a $ as in 
$NAME
or 
$X
. However, the $ is not applied if the variable is enclosed in single quote marks 
(‘ ’). It is applied if the variable is enclosed in double quote marks (“ ”). Let us look 
at some examples. Assume FIRST_NAME stores the string Frank and LAST_NAME 
stores the string Zappa. Here are several different assignment statements and the result 
stored in NAME.
• 
NAME 
=
"$FIRST_NAME $LAST_NAME"
• NAME stores 
Frank Zappa
• 
NAME 
=
'$FIRST_NAME $LAST_NAME'
• NAME stores $
FIRST_NAME $LAST_NAME
• 
NAME 
=
$FIRST_NAME$LAST_NAME
• Name stores FrankZappa, notice that since there is no space on the right hand 
side of the assignment statement, we did not need to place $FIRST_Name 
$LAST_NAME in quote marks


252

Linux with Operating System Concepts
• 
NAME 
=
$FIRST_NAME $LAST_NAME
• Results in an error because there is a space and no quote marks
• 
NAME 
=
"FIRST_NAME LAST_NAME"
• NAME stores 
FIRST_NAME LAST_NAME
because there is no $ preceding the 
variable names
• 
NAME 
=
'FIRST_NAME LAST_NAME'
• NAME stores 
FIRST_NAME LAST_NAME
Once a variable has been given a value, there are several ways to alter it. To assign it a 
different value, just use a new assignment statement. For instance, if X was set to 0, we can 
do 

=
1
to change it. To remove a value from a variable, you can either assign it the NULL 
value which is accomplished by having nothing on the right hand side of the equal sign, 
for instance as
X
=
Alternatively, you can use the unset command as in 
unset X
. Either way, X will no 
longer have a value.
7.3.3 Executing Linux Commands from within Assignment Statements
The VALUE portion of the assignment statement can include executable statements. 
Consider the assignment statement DATE 
=
date. This literally sets the variable DATE 
to store the string 
date
. This would not differ if we enclose date in either “” or ‘’ marks. 
However, if date is placed within either ` ` marks or $() marks, then Bash executes the 
Linux command. So, we revise our previous assignment statement to be DATE 
=
`date` or 
DATE 
=
$(date). This instruction causes the Linux date command to execute and rather 
than sending the output to the terminal window, the output is stored in the variable DATE. 
Notice that we did not use “” or ‘’ marks here. If the right hand side includes multiple 
parts such as literal text, values in variables, and the results of Linux operations, we would 
embed the entire right hand side in “” or ‘’ marks. For instance
DATE 
=
"Hello $FIRST_NAME, today’s date and time is $(date)"
The single quote mark after s is permissible within the double quote marks. We would 
not want to use the single quote marks around the entire right hand side because it would 
treat both $NAME and $(date) literally. For instance
DATE 
=
'Hello $NAME, todays date is ‘date‘'
will cause DATE to store 

Download 5,65 Mb.

Do'stlaringiz bilan baham:
1   ...   92   93   94   95   96   97   98   99   ...   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