Practical 10
Practical 10
1. Write a shell script to count the number of vowels in the given string.
Ans:
#!/bin/bash echo
input_string
vowel_count=0
char="${input_string:$i:1}"
if [[ "$char" == "a" || "$char" == "e" || "$char" == "i" || "$char" == "o" || "$char" == "u" ]];
then vowel_count=$
((vowel_count+1))
fi
done
Output:
2. Write a shell script to check whether the enter age is eligible for vote or
not.
Ans:
Page|1
#!/bin/bash
18 ]
then
else
fi
Output:
X. Program code.
1. Single Decision.
2. Double Decision.
3. Multiple if statements.
Ans:
1. Single Decision:
Page|2
#!/bin/bash echo "Enter the student's
ge 50 ];
passed."
fi
Output:
2. Double Decision:
#!/bin/bash echo "Enter the student's
ge 50 ];
passed."
else
Fi
Output:
Page|3
3. Multiple if statement:
#!/bin/bash echo "Enter the student's
ge 90 ];
then
else
fi
Output:
Ans:
#!/bin/bash
Page|4
echo "Enter a number:"
read number if
[ $number -gt 0 ];
];
then
else
fi
then else
fi
Output:
The single brackets […] is the command The double parentheses ((…)) is the format for
bash arithmetic expansion.
Page|5
Syntax:if Syntax:if
zero” else
Ans:
#!/bin/bash
then
then
else
Fi
Output:
Page|6
XIII. Exercise:
fi Error:
Correct code:
not readable-skipping.”
Fi
Correct code:
Page|7
read x if [$X -nt “/etc/passwd”]; then echo “$X is
fi
Page|8