{"id":1409,"date":"2019-09-05T12:00:00","date_gmt":"2019-09-05T15:00:00","guid":{"rendered":"http:\/\/www.bfnetworks.com.br\/?p=1409"},"modified":"2023-01-15T19:20:35","modified_gmt":"2023-01-15T22:20:35","slug":"comparacoes-shellscript","status":"publish","type":"post","link":"https:\/\/bfnetworks.com.br\/comparacoes-shellscript\/","title":{"rendered":"COMPARANDO STRING, N\u00daMEROS, ARQUIVOS EM SHELLSCRIPT"},"content":{"rendered":"\n

Mostraremos como fazer compara\u00e7\u00f5es num\u00e9ricas, de strings e arquivos em seus comandos em linux ou scripts em shell. <\/p>\n\n\n

NUMBERS<\/h3>\n\n\n
num1 -eq num2<\/td>check if 1st  number is equal to 2nd number<\/td><\/tr>
num1 -ge num2<\/td>checks if 1st  number  is greater than or equal to 2nd number<\/td><\/tr>
num1 -gt num2<\/td>checks if 1st  number is greater than 2nd number<\/td><\/tr>
num1 -le num2<\/td>checks if 1st number is less than or equal to 2nd number<\/td><\/tr>
num1 -lt num2<\/td>checks if 1st  number  is less than 2nd number<\/td><\/tr>
num1 -ne num2<\/td>checks if 1st  number  is not equal to 2nd number<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n

STRINGS<\/h3>\n\n\n
var1 = var2<\/td>checks if var1 is the same as string var2<\/td><\/tr>
var1 != var2<\/td>checks if var1 is not the same as var2<\/td><\/tr>
var1 < var2<\/td>checks if var1 is less than var2<\/td><\/tr>
var1 > var2<\/td>checks if var1 is greater than var2<\/td><\/tr>
-n var1 <\/td>checks if var1 has a length greater than zero<\/td><\/tr>
-z var1 <\/td>checks if var1 has a length of zero<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n

ARQUIVOS<\/h3>\n\n\n
-d file<\/td>checks if the file exists and is it\u2019s a directory<\/td><\/tr>
-e file <\/td>checks if the file exists on system<\/td><\/tr>
-w file<\/td>checks if the file exists on system and if it is writable<\/td><\/tr>
-r file<\/td>checks if the file exists on system and it is readable<\/td><\/tr>
-s file <\/td>checks if the file exists on system and it is not empty<\/td><\/tr>
-f file <\/td>checks if the file exists on system and it is a file<\/td><\/tr>
-O file<\/td>checks if the file exists on system and if it\u2019s is owned by the current user<\/td><\/tr>
-G file <\/td>checks if the file exists and the default group is the same as the current user<\/td><\/tr>
-x file<\/td>checks if the file exists on system and is executable<\/td><\/tr>
file A -nt file B<\/td>checks if file A is newer than file B<\/td><\/tr>
file A -ot file B<\/td>checks if file A is older than file B<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n

FONTE<\/h2>\n\n\n
\n
How to Compare Numbers, Strings and Files in Bash Shell Script<\/a><\/blockquote>