From d1bdcbc14bd5329f00fed6a7f139519f96bea809 Mon Sep 17 00:00:00 2001 From: Benson Muite Date: Tue, 18 Nov 2025 10:29:31 +0300 Subject: [PATCH 1/3] Clearer variable name --- episodes/files/my_first_bash_script.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/episodes/files/my_first_bash_script.sh b/episodes/files/my_first_bash_script.sh index be0891d7..300354a0 100644 --- a/episodes/files/my_first_bash_script.sh +++ b/episodes/files/my_first_bash_script.sh @@ -2,9 +2,9 @@ # This script loops through .txt files, returns the # file name, first line, and last line of the file -for file in *.txt +for filename in *.txt do - echo "$file" - head -n 1 "$file" - tail -n 1 "$file" + echo "$filename" + head -n 1 "$filename" + tail -n 1 "$filename" done From a36b9a4061a5cfe525cc05355bc6235c1389116a Mon Sep 17 00:00:00 2001 From: Benson Muite Date: Tue, 18 Nov 2025 10:33:05 +0300 Subject: [PATCH 2/3] Use clearer variable name --- episodes/04-loops.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/episodes/04-loops.md b/episodes/04-loops.md index 05a0fb38..b30d5789 100644 --- a/episodes/04-loops.md +++ b/episodes/04-loops.md @@ -101,9 +101,9 @@ We have called the variable in this loop `filename` in order to make its purpose Complete the blanks in the for loop below to print the name, first line, and last line of each text file in the current directory. ```bash -___ file in *.txt +___ filename in *.txt __ - echo "_file" + echo "_filename" head -n 1 _______ ____ __ _ _______ ____ @@ -114,11 +114,11 @@ ____ ## Solution ```bash -for file in *.txt +for filename in *.txt do - echo "$file" - head -n 1 "$file" - tail -n 1 "$file" + echo "$filename" + head -n 1 "$filename" + tail -n 1 "$filename" done ``` @@ -140,11 +140,11 @@ Alternatively, rather than running the loop above on the command line, you can s #!/bin/bash # This script loops through .txt files, returns the file name, # first line, and last line of the file -for file in *.txt +for filename in *.txt do - echo "$file" - head -n 1 "$file" - tail -n 1 "$file" + echo "$filename" + head -n 1 "$filename" + tail -n 1 "$filename" done ``` From 65dd11dc5dea25a0b065ae4c7d44b1ddbc5bc3bb Mon Sep 17 00:00:00 2001 From: Benson Muite Date: Fri, 21 Nov 2025 20:03:25 +0300 Subject: [PATCH 3/3] Ensure line breaks match --- episodes/files/my_first_bash_script.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/episodes/files/my_first_bash_script.sh b/episodes/files/my_first_bash_script.sh index 300354a0..00a9f2cb 100644 --- a/episodes/files/my_first_bash_script.sh +++ b/episodes/files/my_first_bash_script.sh @@ -1,6 +1,6 @@ #!/bin/bash -# This script loops through .txt files, returns the -# file name, first line, and last line of the file +# This script loops through .txt files, returns the file name, +# first line, and last line of the file for filename in *.txt do