---
title: Bash
kind: note
description: shell
words: 195
readingMinutes: 1
created: '2024-03-31T20:53:12+02:00'
updated: '2026-06-29T13:10:58+02:00'
---
- An sh-compatible [shell](/notes/unix-shells) that incorporates useful features from the Korn shell (ksh) and the C shell (csh)
## Resources
- [Bash Shell: Take Control of PS1, PS2, PS3, PS4 and PROMPT_COMMAND](https://www.thegeekstuff.com/2008/09/bash-shell-take-control-of-ps1-ps2-ps3-ps4-and-prompt_command/)
  > Your interaction with [Linux](/notes/linux) Bash shell will become very pleasant, if you use PS1, PS2, PS3, PS4, and PROMPT_COMMAND effectively. PS stands for prompt statement. This article will give you a jumpstart on the Linux command prompt environment variables using simple examples.
## Shortcuts
| **Shortcut**   | **Function**                           |
| ---------- | ---------------------------------- |
| `Ctrl`+`L` | Clear screen                       |
| `Ctrl`+`R` | Start or continue a search through |
## Scripting
- [Bash](/notes/bash) scripting titbits:
- `if ! command >/dev/null 2>&1; then ... fi`:
	- If `command` (run without output) returns an exit code greater than 0, then ...
### `if` statements
## 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
