Bash (Bourne Again Shell) is a powerful command-line interpreter commonly used in Linux and Unix environments. Below is a summary of essential Bash commands and scripting concepts.
```
read name echo "Hello, $name!" ```
```
if [ "$name" = "John" ]; then
echo "Hello, John!"
else
echo "Who are you?"
fi
```
* **[[bash:conditionals:case|case Statements]]** - Matches patterns to execute specific commands:
```
case $fruit in
apple) echo "This is an apple";;
banana) echo "This is a banana";;
*) echo "Unknown fruit";;
esac
```
```
for i in 1 2 3; do
echo "Number: $i"
done
```
* **[[bash:loops:while|while Loop]]** - Repeats commands while a condition is true:
```
count=0
while [ $count -lt 5 ]; do
echo "Count: $count"
count=$((count + 1))
done
```
```
greet() {
echo "Hello, $1!"
}
greet "Alice"
```
* **[[bash:functions:return_values|Returning Values]]** - Functions can return status codes using `return`.
```
if [ -f "file.txt" ]; then
echo "File exists"
fi
```
* Common file tests:
* `-f` - Checks if a file exists and is regular.
* `-d` - Checks if a directory exists.
* `-r` - Checks if a file is readable.
* `-w` - Checks if a file is writable.
This summary covers the fundamental concepts of Bash scripting. Each section can be expanded with detailed examples and explanations.