main #1
@@ -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
|
||||
|
||||
|
||||
19
forFile.sh
Normal file
19
forFile.sh
Normal 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
|
||||
|
||||
28
script.sh
Normal file → Executable file
28
script.sh
Normal file → Executable 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
2
scriptFinal.sh
Normal file
@@ -0,0 +1,2 @@
|
||||
script.sh
|
||||
script.sh
|
||||
Reference in New Issue
Block a user