---
title: Bash Scripting for Beginners - Complete Guide to Getting Started - If Statements (Part 5)
kind: note
description: 'Link Video ^44a639 Notes Basic syntax: Checks within single brackets Between variables/literals Comparing integers (equal to) (not equal to) (greater than) (greater than or equal) (less than) (less…'
words: 79
readingMinutes: 1
created: '2024-11-03T00:00:00.000Z'
updated: '2024-11-03T16:27:42+01:00'
website: https://www.youtube.com/watch?v=YrE1Qg-Aw0Q
---
## Link

<https://www.youtube.com/watch?v=YrE1Qg-Aw0Q>

## Video


<div class="youtube-embed"><iframe src="https://www.youtube-nocookie.com/embed/YrE1Qg-Aw0Q" title="Bash Scripting for Beginners: Complete Guide to Getting Started - If Statements (Part 5) - YouTube" loading="lazy" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>

 ^44a639
## Notes
- Basic syntax:
	```shell
	mynum=200
	
	if [ $mynum -eq 200 ]
	then
	    echo "The condition is true."
	else
		echo "The condition is false."
	fi
	```
- Checks within single brackets
	- Between variables/literals
		- Comparing integers
			- `-eq` (equal to)
			- `-ne` (not equal to)
			- `-gt` (greater than)
			- `-ge` (greater than or equal)
			- `-lt` (less than)
			- `-le` (less than or equal)
		- Comparing strings
			- `=` (equal to)
			- `!=` (not equal to)
		- Comparing files
			- `-nt` (newer than)
			- `-ot` (older than)
	- Before the variable/literal
		- `-f` (regular file exists)
		- `-d` (directory exists)
		- `-n` (string has non-zero length)
		- `-z` (string has length zero)
	- Combining checks
		- `&&` (and)
		- `||` (or)
- Checks without brackets
	- `command -v COMMAND` (command exists)
	- `COMMAND` (command exits with return code 0)
- `!` reverses the following condition
