• EnglishSpanishGermanFrenchPolishChinese (Traditional)


EnglishSpanishGermanFrenchPolishChinese (Traditional)

Operating systems, scripting, PowerShell and security

Operating systems, software development, scripting, PowerShell tips, network and security

Menú principal
  • Categorías
  • Cursos
  • Libro de PowerShell (nivel medio)
  • Libro de PowerShell (nivel avanzado)
  • Lo mejor
  • Lo último
  • Proyectos
  • Contactar
Ir al contenido

Operaciones de comparación en Bash

Contenidos

  • Comparación de números enteros
  • Comparación de cadenas de texto

Comparación de números enteros

Shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
 
if [ "$a" -eq "$b" ]; then
echo "\$a es IGUAL que \$b"
fi
 
if [ "$a" -ne "$b" ]; then
echo "\$a NO ES IGUAL que \$b"
fi
 
if [ "$a" -gt "$b" ]; then
echo "\$a es MAYOR que \$b"
fi
 
if [ "$a" -lt "$b" ]; then
echo "\$a es MENOR que \$b"
fi
 
if [ "$a" -ge "$b" ]; then
echo "\$a es MAYOR O IGUAL que \$b"
fi
 
if [ "$a" -le "$b" ]; then
echo "\$a es MENOR O IGUAL que \$b"
fi

Comparación de cadenas de texto

Shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
 
if [ "$a" = "$b" ]; then
echo "\$a es IGUAL que \$b"
fi
 
if [ "$a" == "$b" ]; then
echo "\$a es IGUAL que \$b"
fi
 
if [ "$a" != "$b" ]; then
echo "\$a NO ES IGUAL que \$b"
fi
 
if [ "$a" \> "$b" ]; then
echo "\$a es MAYOR que \$b"
fi
 
if [ "$a" \< "$b" ]; then
echo "\$a es MENOR que \$b"
fi
 
if [ -z "$a" ]; then
echo "\$a ES NULO"
fi
 
if [ -n "$a" ]; then
echo "\$a NO ES NULO"
fi
Publicado el día 4 de febrero de 2020

CATEGORÍAS

Bash

ETIQUETAS

Bash, Echo, Jesús Niño, Jesús Niño Camazón

MÁS

  • Ejercicios de PowerShell: crear usuarios leyendo de un fichero en Ubuntu desde PowerShell con WSL
  • Comprobar si un texto contiene una palabra, extrayendo las palabras del texto mediante Aspell de Linux desde PowerShell con WSL
  • Extraer las palabras de un texto mediante Aspell de Linux desde PowerShell con WSL
  • 3. Gestión del hardware en Linux (nivel intermedio)
  • Pasar parámetros en scripts de Bash
  • Operaciones lógicas en Bash
Jesusninoc utiliza cookies: saber más aquí.