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