From 30381f61e6870e8dece368ecce5a03c9456e1eb3 Mon Sep 17 00:00:00 2001 From: BitwiseOperator Date: Wed, 19 Jun 2024 00:50:40 -0400 Subject: [PATCH] content-update --- .../Knowledge_Base/Coding_&_Scripting/Bash.md | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/docs/Knowledge_Base/Coding_&_Scripting/Bash.md b/docs/Knowledge_Base/Coding_&_Scripting/Bash.md index e7fe37e76..9e81c64ff 100644 --- a/docs/Knowledge_Base/Coding_&_Scripting/Bash.md +++ b/docs/Knowledge_Base/Coding_&_Scripting/Bash.md @@ -20,6 +20,8 @@ done ``` +!!! info "" + #### If statement `$1` here represent the first argument. @@ -30,6 +32,8 @@ fi ``` +!!! info "" + #### If/Else ```bash @@ -42,6 +46,8 @@ fi ``` +!!! info "" + #### Command line arguments Command line arguments are represented like this @@ -54,6 +60,8 @@ This is the first command line argument +!!! info "" + #### Daemonize an execution If you do a ping-sweep with host the command will take about a second to complete. And if you run that against 255 hosts I will take a long time to complete. To avoid this we can just deamonize every execution to make it faster. We use the `&` to daemonize it. @@ -66,6 +74,8 @@ done ``` +!!! info "" + #### Use the output of command It has happened to me several times that I want to input the output of a command into a new command, for example: @@ -87,6 +97,31 @@ ``` + #### Iterate over a file + + This script will iterate over a file and echo out every single line + + ```bash + #!/bin/bash + + for line in $(cat file.txt);do + echo $line + done + ``` + + Another way of writing is this + + ```bash + #!/bin/bash + + while read p; do + echo $p + done