LittleGreenCat / Arithmetic operations in bash
0 gustos
0 bifurcaciones
1 archivos
Última actividad
Арифметические операции в bash
1 | # Returns true if the numbers are equal |
2 | [[ ${arg1} -eq ${arg2} ]] |
3 | |
4 | # Returns true if the numbers are not equal |
5 | [[ ${arg1} -ne ${arg2} ]] |
6 | |
7 | # Returns true if arg1 is less than arg2 |
8 | [[ ${arg1} -lt ${arg2} ]] |
9 | |
10 | # Returns true if arg1 is less than or equal arg2 |
LittleGreenCat / Conditional expressions for string variables in bash
0 gustos
0 bifurcaciones
1 archivos
Última actividad
Условные выражения для строковых переменных в bash
1 | # True if the shell variable varname is set (has been assigned a value). |
2 | [[ -v ${varname} ]] |
3 | |
4 | # True if the length of the string is zero. |
5 | [[ -z ${string} ]] |
6 | |
7 | # True if the length of the string is non-zero. |
8 | [[ -n ${string} ]] |
9 | |
10 | # True if the strings are equal. = should be used with the test command for POSIX conformance. When used with the [[ command, this performs pattern matching as described above (Compound Commands) |
LittleGreenCat / Conditional expressions for files in bash
0 gustos
0 bifurcaciones
1 archivos
Última actividad
Условные выражения для файлов в bash
1 | ## True if file exists. |
2 | [[ -a ${file} ]] |
3 | |
4 | ## True if file exists and is a block special file. |
5 | [[ -b ${file} ]] |
6 | |
7 | ## True if file exists and is a character special file. |
8 | [[ -c ${file} ]] |
9 | |
10 | ## True if file exists and is a directory. |
LittleGreenCat / bash Default values
0 gustos
0 bifurcaciones
1 archivos
Última actividad
Как указать в bash значение переменной по умолчанию
Частенько требуется в bash скрипте указать значение переменной по умолчанию, например если не задано прямо.. Однако не все так просто... Краткий списочек с описанием логики.
# bash one liner
# --------------
x="foo" && echo "${x:-bar} (x = $x)"
# foo (x = foo)
LittleGreenCat / Remove duplicates from an array in bash
0 gustos
0 bifurcaciones
1 archivos
Última actividad
Как в bash удалить повторы из массива
1 | <uniques>=($(echo "${<array>[@]}" | tr ' ' '\\n' | sort -u | tr '\\n' ' ')) |
2 | |
3 | # Пример: |
4 | --> ARRAY=("one" "one" "two" "two" "two" "one" "three") |
5 | --> UNIQUES=($(echo "${ARRAY[@]}" | tr ' ' '\\n' | sort -u | tr '\\n' ' ')) |
6 | --> echo $UNIQUES |
7 | one three two |
8 | |
9 | # улучшенный вариант от Ивана Гришина - https://t.me/JohnMcGru - и правильнее, и короче |
10 | UNIQUES=( $(printf "%s\n" "${ARRAY[@]}" | sort -u ) ) |
LittleGreenCat / Show array length in bash
0 gustos
0 bifurcaciones
2 archivos
Última actividad
Показать в bash длину массива
1 | echo $#<array>[@] |
2 | |
3 | # или если совсем правильно |
4 | |
5 | echo ${#arrayname[@]} |
LittleGreenCat / Bash numerical conditions
0 gustos
0 bifurcaciones
1 archivos
Última actividad
Немного про числовые условия в bash
! EXPRESSION
- The EXPRESSION is false.
-n STRING
- The length of STRING is greater than zero.
-z STRING
- The length of STRING is zero (i.e. it is empty).
STRING1 = STRING2
- STRING1 is equal to STRING2
STRING1 != STRING2
- STRING1 is not equal to STRING2
LittleGreenCat / Bash arithmetic
0 gustos
0 bifurcaciones
1 archivos
Última actividad
1 | echo $((2+2*4)) |
2 | |
3 | Опубликовано в https://t.me/gitgate |
LittleGreenCat / Repeat arguments
0 gustos
0 bifurcaciones
1 archivos
Última actividad
!^
first argument|
!$
last argument
!*
all arguments
!:2
second argument
!:2-3
second to third arguments
Siguiente
Anterior