tags: Bash Bash_Funzioni_Aritmetiche


#!/bin/bash
 
increase=1
decrease=1
 
echo "Addition: 10 + 10 = $((10 + 10))"
echo "Subtraction: 10 - 10 = $((10 - 10))"
echo "Multiplication: 10 * 10 = $((10 * 10))"
echo "Division: 10 / 10 = $((10 / 10))"
echo "Modulus: 10 % 4 = $((10 % 4))"
 
((increase++))
echo "Increase Variable: $increase"
 
((decrease--))
echo "Decrease Variable: $decrease"

Risultato

./Arithmetic.sh
 
Addition: 10 + 10 = 20
Subtraction: 10 - 10 = 0
Multiplication: 10 * 10 = 100
Division: 10 / 10 = 1
Modulus: 10 % 4 = 2
Increase Variable: 2
Decrease Variable: 0

Calcolare la lunghezza di una Variabile

#!/bin/bash
 
htb="HackTheBox"
 
echo ${#htb}

Risultato

./VarLength.sh
 
10

Esempio di Utilizzo

echo -e "\nPinging host(s):"
	for host in $cidr_ips
	do
		stat=1
		while [ $stat -eq 1 ]
		do
			ping -c 2 $host > /dev/null 2>&1
			if [ $? -eq 0 ]
			then
				echo "$host is up."
				((stat--))
				((hosts_up++))
				((hosts_total++))
			else
				echo "$host is down."
				((stat--))
				((hosts_total++))
			fi
		done
	done