🏠 | 💻 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

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

foo is not null

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

Now let's create an empty string

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

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

foo is null

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