Question

1.Write a shell script function called reversal that displays the reverse of a given string. 2.Write...

1.Write a shell script function called reversal that displays the reverse of a given string.

2.Write a shell script function that changes a given string to all CAPS.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1): HomeworkLib.sh (filename)

#!/bin/bash
reversal()
{
#read the input from commandline and store in input variable
read -p "Please enter the input string:" input
#finding the length of input string and store in len_of_string
len_of_string=${#input}
#run a for loop for entire length and print each character from last to first and append in output string variable each time
for (( i=$len_of_string-1; i>=0; i-- ))
do
output="$output${input:$i:1}"
done
#print the output
echo "Reverse of given input string is : $output"
}


#script starts here
#calling the reversal function
reversal

OUTPUT:

[root@njangid ~]# ./HomeworkLib.sh
Please enter the input string:Nicklodean
Reverse of given input string is : naedolkciN

==================================================================

Solution 2):

#!/bin/bash
ConvertToUpperCase()
{
#read the input from commandline and store in input variable
read -p "Please enter the input string : " input
echo "After converting in into Capital letters given input string is : "
echo $input | tr '[a-z]' '[A-Z]'
}
#script starts here
#calling the function
ConvertToUpperCase

OUTPUT: HomeworkLib.sh(filename)

[root@Navin ~]# ./HomeworkLib.sh
Please enter the input string:Hello
After converting in into Capital letters given input string is :
HELLO

Add a comment
Know the answer?
Add Answer to:
1.Write a shell script function called reversal that displays the reverse of a given string. 2.Write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT