Linux with Operating System Concepts



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

comparison filename 
]
and
[ ! 
comparison filename 
]
The comparisons are shown in Table 7.3. The use of ! allows you to negate the result. For 
instance, if you want to test if a file 
does not
exist, you would use 

! –e filename 
].


Shell Scripting

267
In addition to the comparisons in the table, you can also compare two files to see if one 
is older than the other using 
–ot
, one is newer than another using 
–nt
, or two files are the 
same using 
–ef
(useful in the case of links). For instance, the condition 
[ f1 –ot f2 ]
is true if f1 is older than f2.
Here are some examples and their meanings.
• 
[ –f file1.txt ]
is true if file1.txt exists and is a regular file.
• 
[ –h file1.txt ]
is true if file1.txt is a symbolic link to another file.
• 
[[ –r file1.txt && –w file1.txt ]]
is true if file1.txt is both readable and 
writable.
• 
[ ! –e $FILENAME ]
is true if the file whose name is stored in the variable 
FILENAME does not exist.
• 
[ -O file1.txt ]
is true if file1.txt is owned by the current user.
• 
[ ! file1.txt –nt file2.txt ]
is true if file1.txt is not newer than file2.txt.
• 
[ $FILE1 –ef $FILE2 ]
is true if the file whose name is stored in the variable 
FILE1 is the same as the file whose name is stored in the variable FILE2. Notice that 
since FILE1 and FILE2 are variables, we could test [ $FILE1 
==
$FILE2 ] for the same 
physical string, but this would not be true if the two filenames are of files who are 
linked together by a hard link.
There are also comparisons to test a variable. You can test to see if a variable is storing a value 
or stores the special value null. To test for null, use 
[ –z $var ]
and to test to see if it has a 
value (not null), use 
[ –n $var ]
. You can also test for nonnull using 
[ $?variable ]
.
These tests are useful to avoid run-time errors when you attempt to perform an opera-
tion on a variable that may not yet have a value.
TABLE 7.3 
File Operators

Download 5,65 Mb.

Do'stlaringiz bilan baham:
1   ...   97   98   99   100   101   102   103   104   ...   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