In: Computer Science
1. Write a shell code that prints the integers from 80-90
2. Write a shell code that prints the sum of odd integers that are inputted by the user
3. Write a shell code that reads a set of integers {125, 0, 122, 129, 0, 117} and prints {125, 122, 129, 117}
Programming Language: Linux
1. Below is shell code that prints the integers from
80-90:
#Method 1
seq 80 90
#Method 2
for ((a=80; a <= 90 ; a++))
do
echo $a
done
Output:
2. Below is a shell code that prints the sum of odd integers that are inputted by the user.
first_num=0
second_num=0
#Read first odd number:
read -p "Enter the first odd number --> " first_num
#Read second odd number:
read -p "Enter the second number -> " second_num
echo "Sum is: = $((first_num + second_num))"
Output:
3. Below is a shell code that reads a set of integers {125, 0, 122, 129, 0, 117} and prints {125, 122, 129, 117}
#Reads a set of integers
read -a arr
#Print integers except 0 from list
for elem in ${arr[@]}
do
if (( elem != 0 ))
then
echo -n $elem ""
fi
done
Output: