Read names from file and process each in a loop
This commit is contained in:
33
script.sh
33
script.sh
@@ -1,20 +1,27 @@
|
|||||||
|
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
if [ "$name" == "Liana" ]; then
|
|
||||||
echo "Hello Liana!"
|
# Verificăm dacă fișierul a fost dat ca argument
|
||||||
exit 0
|
if [ $# -lt 1 ]; then
|
||||||
elif [ "$name" == "Admin" ]; then
|
echo "Usage: ./script.sh <file_with_names>"
|
||||||
echo "Hello Admin! You have full access."
|
exit 1
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
echo "Hello $name!"
|
|
||||||
exit 0
|
|
||||||
fi
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user