1.7 סקריפטים פתרון
פתרון 1: סקריפט לארגון קבצים
#!/bin/bash
echo "Enter the directory name:"
read dir
if [ -d "$dir" ]; then
ls "$dir"
else
echo "Directory does not exist!"
history > error.log
fi
פתרון 2: סקריפט שמחשב את סך כל השורות בקבצים
#!/bin/bash
echo "Enter the file names (separated by spaces):"
read files
total_lines=0
for file in $files; do
if [ -f "$file" ]; then
lines=$(wc -l < "$file")
total_lines=$((total_lines + lines))
else
echo "$file does not exist."
fi
done
echo "Total lines: $total_lines"
פתרון 3: סקריפט עם פונקציה שמחברת שני מספרים
#!/bin/bash
add_numbers() {
result=$(( $1 + $2 ))
echo "The sum is: $result"
}
echo "Enter the first number:"
read num1
echo "Enter the second number:"
read num2
add_numbers $num1 $num2