From 777b6b567dc212835e7213991380e00320d6d2c4 Mon Sep 17 00:00:00 2001 From: Liana Date: Sun, 14 Dec 2025 19:25:22 +0000 Subject: [PATCH 01/11] Use variables in bash script --- script.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) mode change 100644 => 100755 script.sh diff --git a/script.sh b/script.sh old mode 100644 new mode 100755 index d03c099..8d05b68 --- a/script.sh +++ b/script.sh @@ -1 +1,11 @@ -fisierul nu exista dar voi incerca sa il afisez + +#!/bin/bash + +name="Liana" +course="DevOps Bash" + + +echo "Hello, $name!" +echo "You are learning $course" + + From 08eba2eccc45dc4563866ba41d9ce7eba7e33371 Mon Sep 17 00:00:00 2001 From: Liana Date: Sun, 14 Dec 2025 19:49:15 +0000 Subject: [PATCH 02/11] Add if/else conditions --- script.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/script.sh b/script.sh index 8d05b68..46e5aef 100755 --- a/script.sh +++ b/script.sh @@ -1,5 +1,40 @@ #!/bin/bash + ##1 +if [ -z "$1" ]; then + echo "Usage: ./script.sh " + exit 1 +fi + +name="$1" + +echo "Hello, $name!" +echo "Welcome to DevOps Bash scripting." + + +##2 + +if [-z "$1"]; then +echo "Usage: ./script.sh " +exit 1 +fi + +name="$1" + +if ["$name == "Liana"]; then + +echo "Hello $name! You ar awesome!" +else +echo "Hello, $name!" +fi +exit 0 + + + + + + + name="Liana" course="DevOps Bash" From 68d1d59b166965fd0eb95d697a4282367dbad6b0 Mon Sep 17 00:00:00 2001 From: Liana Date: Sun, 14 Dec 2025 20:02:19 +0000 Subject: [PATCH 03/11] Add if exemple --- script.sh | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/script.sh b/script.sh index 46e5aef..eaef600 100755 --- a/script.sh +++ b/script.sh @@ -2,7 +2,7 @@ #!/bin/bash ##1 if [ -z "$1" ]; then - echo "Usage: ./script.sh " + echo "Usage: ./script.sh $name" exit 1 fi @@ -12,35 +12,8 @@ echo "Hello, $name!" echo "Welcome to DevOps Bash scripting." -##2 - -if [-z "$1"]; then -echo "Usage: ./script.sh " -exit 1 -fi - -name="$1" - -if ["$name == "Liana"]; then - -echo "Hello $name! You ar awesome!" -else -echo "Hello, $name!" -fi -exit 0 - - - -name="Liana" -course="DevOps Bash" - - -echo "Hello, $name!" -echo "You are learning $course" - - From fe7b8c609123b4a97d3c1bee6c9a93714b776949 Mon Sep 17 00:00:00 2001 From: Liana Date: Sun, 14 Dec 2025 20:14:48 +0000 Subject: [PATCH 04/11] Add mare ex .if condition --- script.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/script.sh b/script.sh index eaef600..a3f4edc 100755 --- a/script.sh +++ b/script.sh @@ -1,15 +1,15 @@ #!/bin/bash - ##1 -if [ -z "$1" ]; then - echo "Usage: ./script.sh $name" - exit 1 +##Daca numarul total de argumente are mai putin de 2 argumente: +if [ $# -lt 2 ]; then + echo "Usage: ./script.sh " + exit 1 fi -name="$1" +first_name="$1" +last_name="$2" -echo "Hello, $name!" -echo "Welcome to DevOps Bash scripting." +echo "Hello, $first_name $last_name!" From 3ff5d29cdebf666e91f47921970956b86d7b95f7 Mon Sep 17 00:00:00 2001 From: Liana Date: Sun, 14 Dec 2025 20:16:53 +0000 Subject: [PATCH 05/11] Add another ex .if condition --- script.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/script.sh b/script.sh index a3f4edc..cc8f447 100755 --- a/script.sh +++ b/script.sh @@ -1,15 +1,12 @@ #!/bin/bash -##Daca numarul total de argumente are mai putin de 2 argumente: -if [ $# -lt 2 ]; then - echo "Usage: ./script.sh " + +if [ $# -eq 0 ]; then + echo "Usage: ./script.sh " exit 1 fi -first_name="$1" -last_name="$2" - -echo "Hello, $first_name $last_name!" +echo "Hello, all of you: $@" From 96b1188222209e3f8e1cf36577a71aaafe9e51e4 Mon Sep 17 00:00:00 2001 From: Liana Date: Sun, 14 Dec 2025 20:22:29 +0000 Subject: [PATCH 06/11] Add if/else ex. --- script.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/script.sh b/script.sh index cc8f447..7b6c465 100755 --- a/script.sh +++ b/script.sh @@ -1,12 +1,16 @@ #!/bin/bash - -if [ $# -eq 0 ]; then - echo "Usage: ./script.sh " - exit 1 +if [ "$name" == "Liana" ]; then + echo "Hello Liana!" + exit 0 +elif [ "$name" == "Admin" ]; then + echo "Hello Admin! You have full access." + exit 0 +else + echo "Hello $name!" + exit 0 fi -echo "Hello, all of you: $@" From 64075621037e26735f5db61a96216582b4b9e19a Mon Sep 17 00:00:00 2001 From: Liana Date: Sun, 14 Dec 2025 20:29:19 +0000 Subject: [PATCH 07/11] Add a file scriptFinal.sh --- scriptFinal.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 scriptFinal.sh diff --git a/scriptFinal.sh b/scriptFinal.sh new file mode 100644 index 0000000..8914db0 --- /dev/null +++ b/scriptFinal.sh @@ -0,0 +1,2 @@ +script.sh +script.sh From 648fd1478ce3d85ea1ffebfe1ecc3f420a9a2505 Mon Sep 17 00:00:00 2001 From: Liana Date: Sun, 14 Dec 2025 20:34:11 +0000 Subject: [PATCH 08/11] Add file forFile.sh --- forFile.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 forFile.sh diff --git a/forFile.sh b/forFile.sh new file mode 100644 index 0000000..ebe92a7 --- /dev/null +++ b/forFile.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Verificăm dacă există cel puțin un argument +if [ $# -lt 1 ]; then + echo "Usage: ./script.sh [name2 ... nameN]" + exit 1 +fi + +# Loop prin toate argumentele folosind $@ +for name in "$@"; do + if [ "$name" == "Liana" ]; then + echo "Hello, $name! You are awesome!" + else + echo "Hello, $name!" + fi +done + +exit 0 + From 532cf15638901555db44e2018a0f6598503fcb8c Mon Sep 17 00:00:00 2001 From: Liana Date: Sun, 14 Dec 2025 20:39:35 +0000 Subject: [PATCH 09/11] Add explanations in the file README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 8612768..870ee56 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,9 @@ chmod +x script.sh ./script.sh +## Explications: +$# -> nr total de argumente +$@ -> toate argumentele ca lista +for name in "$@" -> itereaza prin fiecare argument +exit 0, exit 1 -> cod de succes, eroare From 90c1e28700815898df7261782efbf96b1f44eb75 Mon Sep 17 00:00:00 2001 From: Liana Date: Sun, 14 Dec 2025 20:44:41 +0000 Subject: [PATCH 10/11] Read names from file and process each in a loop --- names.txt | 5 +++++ script.sh | 33 ++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 names.txt diff --git a/names.txt b/names.txt new file mode 100644 index 0000000..13c0fce --- /dev/null +++ b/names.txt @@ -0,0 +1,5 @@ +Liana +Ion +Maria +Alex + diff --git a/script.sh b/script.sh index 7b6c465..6b6b0fb 100755 --- a/script.sh +++ b/script.sh @@ -1,20 +1,27 @@ - #!/bin/bash -if [ "$name" == "Liana" ]; then - echo "Hello Liana!" - exit 0 -elif [ "$name" == "Admin" ]; then - echo "Hello Admin! You have full access." - exit 0 -else - echo "Hello $name!" - exit 0 + +# Verificăm dacă fișierul a fost dat ca argument +if [ $# -lt 1 ]; then + echo "Usage: ./script.sh " + exit 1 fi +file="$1" +# Verificăm dacă fișierul există +if [ ! -f "$file" ]; then + echo "File '$file' does not exist!" + exit 1 +fi +# Loop prin fiecare linie (nume) din fișier +while IFS= read -r name; do + if [ "$name" == "Liana" ]; then + echo "Hello, $name! You are awesome!" + else + echo "Hello, $name!" + fi +done < "$file" - - - +exit 0 From cf1f81f1ef630225db928a79162024cfb58d9945 Mon Sep 17 00:00:00 2001 From: Liana Date: Tue, 16 Dec 2025 18:27:52 +0000 Subject: [PATCH 11/11] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 870ee56..539f53e 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ This Repo contains simple Bash scripts created during my DevOps learning. ##Scripts -- #!/bin/bash -- script.sh - first Bash script +- #!/bin/bash +- script.sh - first Bash script ## How to Run: chmod +x script.sh