Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
# Name: Jerry Hook
# Serial Number: 25
# Assignment Number: 1
# Due Date: 02/18/19
echo "The function of this script is to:"
echo "1. Display the numbers."
echo "2. Add and multiply 3 numbers."
echo "3. Find all odd and even numbers between 1 and the first argument."
echo "4. Indicate whether the numbers entered are one-digit numbers, two-digit numbers or three-digit numbers."
echo "5. Display all prime numbers between 1 and the second number."
echo
read -p "Enter the first number: " num1
read -p "Enter the second number: " num2
read -p "Enter the third number: " num3
echo
echo "The numbers are $num1 $num2 $num3"
echo
sum=$((num1+num2+num3))
echo "$num1 + $num2 + $num3 = $sum"
echo
prod=$((num1*num2*num3))
echo "$num1 * $num2 * $num3 = $prod"
echo
echo "All odd numbers between 1 and $num1"
echo
for i in {1..num1}
do
rem=$(($i % 2))
if [ "$rem" -ne "0" ]; then
echo -n "$i "
fi
done
echo
echo "All even numbers between 1 and $num1"
echo
for i in {1..num1}
do
rem=$(($i % 2))
if [ "$rem" -eq "0" ]; then
echo -n "$i "
fi
done
echo
digits1={#num1}
if [ "digits1" -eq "1" ]; then
echo "$num1 is a one-digit number"
fi
if [ "digits1" -eq "2" ]; then
echo "$num1 is a two-digit number"
fi
if [ "digits1" -eq "3" ]; then
echo "$num1 is a three-digit number"
fi
echo
digits2={#num2}
if [ "digits2" -eq "1" ]; then
echo "$num2 is a one-digit number"
fi
if [ "digits2" -eq "2" ]; then
echo "$num2 is a two-digit number"
fi
if [ "digits2" -eq "3" ]; then
echo "$num2 is a three-digit number"
fi
echo
digits3={#num3}
if [ "digits3" -eq "1" ]; then
echo "$num3 is a one-digit number"
fi
if [ "digits3" -eq "2" ]; then
echo "$num3 is a two-digit number"
fi
if [ "digits3" -eq "3" ]; then
echo "$num3 is a three-digit number"
fi
echo
for i in {1..num2}
do
flag=0
for j in {2..num2}
do
if[ 'expr $i % $j' -eq 0 ]; then
flag=1
fi
done
if[ flag -eq 0 ]; then
echo -n "$i "
fi
done
echo
echo "End of script"
echo
echo "Jerry Hook - 2-18-2019"
exit 0
echo -en "\ec"
echo "Script to find prime number"
echo Enter a number
num=50
flag=0
for((i=2;i<=num/2;i++))
do
flag=$((flag+1))
done
if [ "$flag" -gt 0 ]
then
echo "Not prime $flag $i"
else
echo "prime"
fi
echo "enter the number"
read n
q=$n
a=0
while [ $q – gt 0 ]
do
r= `expr $q % 10 `
q= `expr $q / 10 `
a=`expr $a + $r /* $r /*$r `
done
if [ $a=$n ]
then
echo "the number $n is armstrong number"
else
echo "the number $n is not armstrong number"
fi
# Hello World Program in Bash Shell
set BUILDCONFIGURATION ="node+postgrass"
echo "here we go!"
if [ -z $BUILDCONFIGURATION == *"node\+postgres"* ]
then
echo true
else
echo false
fi
function watch() {
local varName=$1
local prefix=$2 # Optionnal
local var
eval var=\$$varName
[[ $# -ge 2 ]] && echo "${prefix} : ${var}" || echo "${varName} : ${var}"
}
function test() {
local var a;
a=42
watch a
watch a "a currently has the value"
}
test
function watch() {
local varName=$1
local var
eval var=\$$varName
[[ $# -ge 2 ]] && echo "$2 : ${var}" || echo "${varName} : ${var}"
}
function test() {
echo "test()"
local var a;
a=42
watch a
watch a "a currently has the value"
echo "~test()"
}
test