From b120926aa464e7cb10d603da5cdcb51e1cc76235 Mon Sep 17 00:00:00 2001
From: "alexis.dereeper_ird.fr" <alexis.dereeper@ird.fr>
Date: Wed, 27 Nov 2024 20:52:17 +0000
Subject: [PATCH] Update bash-9-scripting.md

---
 docs/pages/bash/bash-9-scripting.md | 32 ++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/docs/pages/bash/bash-9-scripting.md b/docs/pages/bash/bash-9-scripting.md
index 3e6d4fb..d0d8aed 100644
--- a/docs/pages/bash/bash-9-scripting.md
+++ b/docs/pages/bash/bash-9-scripting.md
@@ -108,5 +108,35 @@ echo $var2
     else
       echo "Directory '$directory' does not exist."
     fi
+    ```
+
+    ## For loop
+
+!!! question "Write a bash script called `count4.sh` that does the same as previously, and also report the number of characters for each file"
+
+??? example "Click to show the solution"
+    ```bash
+    #!/bin/bash
+
+    # directory variable
+    directory=$1
+
+    if [ -d "$directory" ]; then
+    # count the number of files
+     file_count=$(ls -1 "$directory" | wc -l)
+     echo "Directory '$directory' contains $file_count files."
+     for file in `ls $directory`
+      do
+       if [ -f "$directory/$file" ]; then
+        number_lines=$(cat "$directory/$file" | wc -c)
+        echo $file $number_lines
+       fi
+      done
+    else
+      echo "Directory '$directory' does not exist."
+    fi
+    ```
+
 
-    ```
\ No newline at end of file
+!!! question "Write a bash script called `count5.sh` that does the same as previously, and also report the total number
+of characters contained in all files"
\ No newline at end of file
-- 
GitLab