From 008325beaa551068f941b8424bc7ffbfa5ebdaae Mon Sep 17 00:00:00 2001 From: Benson Muite Date: Wed, 3 Apr 2024 14:48:05 +0300 Subject: [PATCH 1/2] Add quotes to shell script - Use consistent syntax - Make it easier to read the example without scrolling --- episodes/04-loops.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/episodes/04-loops.md b/episodes/04-loops.md index fef6c29e..05a0fb38 100644 --- a/episodes/04-loops.md +++ b/episodes/04-loops.md @@ -138,12 +138,13 @@ 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 +# This script loops through .txt files, returns the file name, +# first line, and last line of the file for file in *.txt do - echo $file - head -n 1 $file - tail -n 1 $file + echo "$file" + head -n 1 "$file" + tail -n 1 "$file" done ``` From b1bfb028a74d7964ad75ad4eb8a4d504a686fa90 Mon Sep 17 00:00:00 2001 From: Benson Muite Date: Wed, 3 Apr 2024 14:52:21 +0300 Subject: [PATCH 2/2] Ensure script matches main text --- episodes/files/my_first_bash_script.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/episodes/files/my_first_bash_script.sh b/episodes/files/my_first_bash_script.sh index 4cd0315f..be0891d7 100644 --- a/episodes/files/my_first_bash_script.sh +++ b/episodes/files/my_first_bash_script.sh @@ -1,8 +1,10 @@ #!/bin/bash +# This script loops through .txt files, returns the +# file name, first line, and last line of the file -for filename in *.txt +for file in *.txt do - echo $filename - head -n 5 $filename - tail -n 5 $filename -done \ No newline at end of file + echo "$file" + head -n 1 "$file" + tail -n 1 "$file" +done