Professional Documents
Culture Documents
1) Write a bash shell script to reverse a string, which is given as the argument.
len=${#input}
for (( i=$len-1; i>=0; i-- ))
do
reverse="$reverse${input:$i:1}"
done
echo "$reverse"
---------------------------------------------
--Give the execute permission to the file by the command chmod +x example.sh
--run the shell script by the command ./example.sh <string>
str="*"
for i in 1 2 3 4 5
do
echo "$str"
str="$str *"
done
-------------------------------------------
3) Write a sample shell script to find whether an input number is palindrome or not.
Ans)
---------------------------------------
#!/bin/bash
echo -n "Enter number : "
read n
4) Your task is to create a shell script that is able to backup all the C program files in your current
directory.
The algorithm is as follows:
If a backup directory does not exist, then prompt the user if they would like to make one.
-- If the user responds "y" or "yes" in either capitals or lowercase, then make the backup
directory (in your current working directory)
-- If the user responds "n" or "no" in either capitals or lowercase, then produce a
message that no directory was created
-- otherwise, print a message that an invalid response was entered
5) Given a column title as appears in an Excel sheet, return its corresponding column number.
6) Write a shell script to calculate roots of a quadratic equation using shell script.
7) Write a function that takes a directory name as an argument and writes to standard output the
maximum of the lengths of all filenames in that directory. If the functions argument is not a
directory
name, write an error message to standard output and exit with nonzero status.
8) Find out the anagrams in a string for a pattern given as an argument using shell script.
9) Find out the GCD of two integral numbers given as arguments in shell script.