Merge pull request 'main' (#1) from main into first-script

Reviewed-on: Liana/Bash_Scripts#1
This commit was merged in pull request #1.
This commit is contained in:
2025-12-16 18:31:38 +00:00
5 changed files with 60 additions and 3 deletions

View File

@@ -2,11 +2,16 @@
This Repo contains simple Bash scripts created during my DevOps learning. This Repo contains simple Bash scripts created during my DevOps learning.
##Scripts ##Scripts
- #!/bin/bash - #!/bin/bash
- script.sh - first Bash script - script.sh - first Bash script
## How to Run: ## How to Run:
chmod +x script.sh chmod +x script.sh
./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

19
forFile.sh Normal file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
# Verificăm dacă există cel puțin un argument
if [ $# -lt 1 ]; then
echo "Usage: ./script.sh <name1> [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

5
names.txt Normal file
View File

@@ -0,0 +1,5 @@
Liana
Ion
Maria
Alex

28
script.sh Normal file → Executable file
View File

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

2
scriptFinal.sh Normal file
View File

@@ -0,0 +1,2 @@
script.sh
script.sh