🏠 | 💻 IT | Linux | Bash |

Bash Conditional operators

The most important thing is to keep track of the indents before and after the square brackets.

#!/bin/bash # We accept the first parameter from the terminal mode=$1 echo "start" if [[ $mode = 1 ]]; then echo "First" elif [ $mode = 2 ]; then echo "Second" else echo "Try using different parameter" fi

Comparison operators

-n - string is not zero

-z is a null string, that is, it has zero length

Create a non-empty string and apply -t and -z to it

[ -n "$foo" ] && echo "foo is not null"

foo is not null

[ -z "$foo" ] && echo "foo is null"

Now let's create an empty string

[ -n "$foo" ] && echo "foo is not null"

[ -z "$foo" ] && echo "foo is null"

foo is null

Статьи о Bash
Bash Scripting
-eq -gt …: Операторы сравнения
Цикл while
Переход на новую строку
Арифметические операции
Передать файл или пароль по SFTP в Bash скрипте
Errors Bash
Share in social media: