Read names from file and process each in a loop

This commit is contained in:
2025-12-14 20:44:41 +00:00
parent 532cf15638
commit 90c1e28700
2 changed files with 25 additions and 13 deletions

View File

@@ -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 <file_with_names>"
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