diff --git a/IT/Scripting.md b/IT/Scripting.md index 0ad52a2..f183f40 100644 --- a/IT/Scripting.md +++ b/IT/Scripting.md @@ -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:
```
sudo chown `id -u` /some/directory
``` | ## 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 | | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |