🏠 | 💻 | 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
Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: