vault backup: 2024-05-30 18:15:46
This commit is contained in:
parent
848928c098
commit
ab40593eae
@ -29,23 +29,33 @@ In Bash, different styles of quotes (or a backtick) mean different things:
|
|||||||
| Backtick (\`) | While a backtick is not technically a quotation mark, it's included here. Backticks are used to substitute the output a command in a location:<br>```<br>sudo chown `id -u` /some/directory<br>``` |
|
| Backtick (\`) | While a backtick is not technically a quotation mark, it's included here. Backticks are used to substitute the output a command in a location:<br>```<br>sudo chown `id -u` /some/directory<br>``` |
|
||||||
## Conditionals
|
## Conditionals
|
||||||
A basic if statement in bash looks like this:
|
A basic if statement in bash looks like this:
|
||||||
```
|
```bash
|
||||||
if somecommand; then
|
if somecommand; then
|
||||||
# The code here will be run if somecommand has an exit code of 0
|
# The code here will be run if somecommand has an exit code of 0
|
||||||
fi
|
fi
|
||||||
```
|
```
|
||||||
Note that the if statement is terminated by `fi`. This is fairly standard throughout bash scripting, where the blocks are closed with the reverse text used to open them.
|
Note that the if statement is terminated by `fi`. This is fairly standard throughout bash scripting, where the blocks are closed with the reverse text used to open them.
|
||||||
|
|
||||||
You can also make use of `else` for more complex conditional logic:
|
You can also make use of `else` or `elif` for more complex conditional logic:
|
||||||
```
|
```bash
|
||||||
if somecommand; then
|
if somecommand; then
|
||||||
# If the command succeeds, run this code
|
# If the command succeeds, run this code
|
||||||
else
|
else
|
||||||
# If the command fails, run this code.
|
# If the command fails, run this code.
|
||||||
fi
|
fi
|
||||||
```
|
```
|
||||||
|
`elif`:
|
||||||
|
```bash
|
||||||
|
if [ "$1" = "hello" ]; then
|
||||||
|
echo "hello yourself"
|
||||||
|
elif [ "$1" = "goodbye" ]; then
|
||||||
|
echo "nice to have met you"
|
||||||
|
echo "I hope to see you again"
|
||||||
|
else
|
||||||
|
echo "I didn't understand that"
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
If you need even more
|
|
||||||
## Commands
|
## Commands
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
Loading…
Reference in New Issue
Block a user