From 847beb446f94da15aac5191d804c0f8d3ade7a56 Mon Sep 17 00:00:00 2001 From: Hizenberg469 Date: Wed, 20 Nov 2024 12:27:31 +0530 Subject: [PATCH] update --- Bash-Scripting.txt | 107 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/Bash-Scripting.txt b/Bash-Scripting.txt index 2b33dcf..9737ad4 100644 --- a/Bash-Scripting.txt +++ b/Bash-Scripting.txt @@ -192,4 +192,109 @@ non-zero value. We can exit script using exit command. - exit command can be used with number 0 - 255. \ No newline at end of file + exit command can be used with number 0 - 255. + +-> If Statement + + if[ condition ]; then + .... + elif[ condition ]; then + .... + elif[ condition ]; then + .... + else + .... + fi + + * AND with if statement ? + + if[ condition ] && [ condition ]; then + .... + fi + + * OR wiht if statement ? + + if[ condition ] || [ condition ]; then + .... + fi + + * Negate if condition + + if[ !condition ]; then + .... + fi + + if![ condition ]; then + .... + fi + +-> Mathematical comparison: + + * Operands + + $ -eq equal to + $ -ne not equal to + $ -gt greater than + $ -lt less than + $ -ge greater than or equal to + $ -le less than or equal to + + Examples: + + if [ $VAR -eq 5 ]; then + if [ $VAR -gt 7 ]; then + if [ $VAR -eq 5 ] && [ $COUNT -ne 1 ]; then + + + +-> String Comaparison + + * Comapare two strings + [ "$STR1" = "$STR2" ] + [ "$STR1" != "$STR2" ] + + [ "$STR1" = "hello" ] + [ "$STR1" != "hello" ] + + * Compare two strings - quotation marks? + Bash can handle it in another way [[ ]] + + [[ $STR1 = $STR2 ]] + [[ $STR1 != $STR2 ]] + + [[ $STR1 = "hello" ]] + [[ $STR1 != "hello ]] + + This is not widely used and most scripts + are using quotation marks with single + brackets + + * Test if string is empty + + [ -z "$STR1" ] returns true if STR1 holds + an empty string + + [[ -z $STR1 ]] possible, but not widely used + + [ -n "$STR1" ] returns true if STR1 holds + a non-empty string + + [[ -n $STR1 ]] possible, but not widely used + + * Alphabetically compare two strings + + [[ $STR1 > $STR2 ]] + + [[ $STR1 < $STR2 ]] + + No choice!!! + + * Wildcards + + [[ $STR1 == string-with-wildcards ]] + + * Regular expression + + [[ $STR1 =~ $regex ]] + + \ No newline at end of file