diff --git a/helloworld.sh b/helloworld.sh new file mode 100755 index 0000000000000000000000000000000000000000..bf3f7c53f320eaa5472fcadc890a8fd2e94564b0 --- /dev/null +++ b/helloworld.sh @@ -0,0 +1,8 @@ +#/bin/bash +lsOutput=$(ls -lrt) +echo $lsOutput + +echo "Enter a number " +read number +echo "It's $number" + diff --git a/week3/exercise3_compare.sh b/week3/exercise3_compare.sh new file mode 100755 index 0000000000000000000000000000000000000000..698cf70bba23487af950c9dd885897ed2ce80f25 --- /dev/null +++ b/week3/exercise3_compare.sh @@ -0,0 +1,17 @@ +echo "Enter a number: " +read num1 +echo "Enter another number: " +read num2 + +if [ "$num1" = "$num2" ]; then + echo "$num1 equals to $num2" +else + if [ "$num1" -gt "$num2" ]; then + echo "$num1 is greater than $num2" + else + echo "$num1 is smaller than $num2" + fi +fi + +sumNum=$((num1 + num2)) +echo "$sumNum" \ No newline at end of file diff --git a/week3/exercise3_if.sh b/week3/exercise3_if.sh new file mode 100755 index 0000000000000000000000000000000000000000..2492fbbb341d8e106663c4caf59de67cd1942210 --- /dev/null +++ b/week3/exercise3_if.sh @@ -0,0 +1,8 @@ +echo "Enter a number: " +read num + +if [ $((num % 2)) -eq 0 ]; then + echo "$num is even" +else + echo "$num is odd" +fi \ No newline at end of file diff --git a/week3/exercise3_loop.sh b/week3/exercise3_loop.sh new file mode 100755 index 0000000000000000000000000000000000000000..1a50ddd5dd332c904e0df0ad29357cd31d5d858a --- /dev/null +++ b/week3/exercise3_loop.sh @@ -0,0 +1,9 @@ +numbers=() +sum=0 +for ((i=1; i<=10; i++)); do + read -p "Enter number $i: " num + numbers+=("$num") + sum=$((sum+num)) +done + +echo "The sum of the array is $sum" \ No newline at end of file