From 7d391db0d9740b81c442f3c090adb2d85410ce50 Mon Sep 17 00:00:00 2001 From: waldek Date: Fri, 20 May 2022 15:56:52 +0200 Subject: [PATCH] moves coding challenge to end of chapter --- advanced/learning_bash_scripting.md | 63 +++++++++++++++-------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/advanced/learning_bash_scripting.md b/advanced/learning_bash_scripting.md index 80dda73..b91b64c 100644 --- a/advanced/learning_bash_scripting.md +++ b/advanced/learning_bash_scripting.md @@ -812,6 +812,38 @@ if [ "$num" -lt "300" ]; then fi ``` +## A *modern* version of `test` + +I'll be the first to admit that the syntax of `bash` can be confusing and is rarely reader friendly. +A nice, but brief, explication of the nuances of single and double brackets can be found in [this](https://unix.stackexchange.com/questions/306111/what-is-the-difference-between-the-bash-operators-vs-vs-vs) stack overflow post. +The double bracket command are called [compound commands](https://www.gnu.org/software/bash/manual/html_node/Compound-Commands.html). + +### `[[ ]]` + +``` +waldek@debian:~$ [[ 3 = [[:digit:]] ]] ; echo $? +0 +waldek@debian:~$ [ 3 = [[:digit:]] ] ; echo $? +1 +``` +TODO + +### `(( ))` + +TODO + +### `&&` and `||` + +``` +waldek@debian:~$ test true == true && echo "yes sir!" || echo "nope..." +yes sir! +waldek@debian:~$ test true == false && echo "yes sir!" || echo "nope..." +nope... +waldek@debian:~$ +``` + +[Ryan's tutorials](https://ryanstutorials.net/bash-scripting-tutorial/bash-if-statements.php) + # Coding challenge - File information Write a script that takes one argument which should be a valid file path. @@ -868,37 +900,6 @@ fi -## A *modern* version of `test` - -I'll be the first to admit that the syntax of `bash` can be confusing and is rarely reader friendly. -A nice, but brief, explication of the nuances of single and double brackets can be found in [this](https://unix.stackexchange.com/questions/306111/what-is-the-difference-between-the-bash-operators-vs-vs-vs) stack overflow post. -The double bracket command are called [compound commands](https://www.gnu.org/software/bash/manual/html_node/Compound-Commands.html). - -### `[[ ]]` - -``` -waldek@debian:~$ [[ 3 = [[:digit:]] ]] ; echo $? -0 -waldek@debian:~$ [ 3 = [[:digit:]] ] ; echo $? -1 -``` -TODO - -### `(( ))` - -TODO - -### `&&` and `||` - -``` -waldek@debian:~$ test true == true && echo "yes sir!" || echo "nope..." -yes sir! -waldek@debian:~$ test true == false && echo "yes sir!" || echo "nope..." -nope... -waldek@debian:~$ -``` - -[Ryan's tutorials](https://ryanstutorials.net/bash-scripting-tutorial/bash-if-statements.php) # Loops - A variety of ways to perform repetitive tasks.