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>``` |
|
||||
## Conditionals
|
||||
A basic if statement in bash looks like this:
|
||||
```
|
||||
```bash
|
||||
if somecommand; then
|
||||
# The code here will be run if somecommand has an exit code of 0
|
||||
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.
|
||||
|
||||
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 the command succeeds, run this code
|
||||
else
|
||||
# If the command fails, run this code.
|
||||
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
|
||||
| Command | Description |
|
||||
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
|
Loading…
Reference in New Issue
Block a user