COMPARANDO STRING, NÚMEROS, ARQUIVOS EM SHELLSCRIPT

Mostraremos como fazer comparações numéricas, de strings e arquivos em seus comandos em linux ou scripts em shell.

NUMBERS

num1 -eq num2check if 1st  number is equal to 2nd number
num1 -ge num2checks if 1st  number  is greater than or equal to 2nd number
num1 -gt num2checks if 1st  number is greater than 2nd number
num1 -le num2checks if 1st number is less than or equal to 2nd number
num1 -lt num2checks if 1st  number  is less than 2nd number
num1 -ne num2checks if 1st  number  is not equal to 2nd number

STRINGS

var1 = var2checks if var1 is the same as string var2
var1 != var2checks if var1 is not the same as var2
var1 < var2checks if var1 is less than var2
var1 > var2checks if var1 is greater than var2
-n var1 checks if var1 has a length greater than zero
-z var1 checks if var1 has a length of zero

ARQUIVOS

-d filechecks if the file exists and is it’s a directory
-e file checks if the file exists on system
-w filechecks if the file exists on system and if it is writable
-r filechecks if the file exists on system and it is readable
-s file checks if the file exists on system and it is not empty
-f file checks if the file exists on system and it is a file
-O filechecks if the file exists on system and if it’s is owned by the current user
-G file checks if the file exists and the default group is the same as the current user
-x filechecks if the file exists on system and is executable
file A -nt file Bchecks if file A is newer than file B
file A -ot file Bchecks if file A is older than file B

FONTE

https://www.linuxtechi.com/compare-numbers-strings-files-in-bash-script/

Publicar comentário