diff --git a/README.md b/README.md index 8612768..539f53e 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,16 @@ 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 ./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 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 + 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 old mode 100644 new mode 100755 index d03c099..6b6b0fb --- a/script.sh +++ b/script.sh @@ -1 +1,27 @@ -fisierul nu exista dar voi incerca sa il afisez +#!/bin/bash + +# 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 + 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