You are on page 1of 2

Unix Home Assignment - 1

Lab Cycle -2
Bash Shell Exercises-1
1. Perform the following
o Display all the variables available in the current shell
o Display all the environment variables available in the current shell
2. Execute the following shell variables
o $HOME
o $PATH
o Which variable instructs the shell about the route it should follow to locate
any shell command?
o To include a directory /usr/xpg4/bin in your search list how you will reassign
the PATH variable
o $MAIL
o $MAILCHECK
o $IFS
o $LOGNAME
o $TERM
o $SHELL
o How you can confirm the contents of $IFS Variable by taking its octal dump Hin
t: od â bc
o To customize our shell environment how do you set, unset, and display options
3. Perform the following for your login
o Disallow ctrl+d to exit the shell for your login
o Does not allow redirection to clobber exiting file
o Use Vi for command-line editing and history file
o Disable wildcard expansion
o Change the interrupt key ^c to ^l
o How do you assign short-names for commands you may be using quite frequently?
Perform it on ls -l.
o Change the end of file key to ^a
o Display cal and your current directory every time you login
4. How do you edit the current and previous command lines?
o Perform with an example by deleting a character, 3 characters and a word.
o How do you paste this word elsewhere in the line?
o How do you recall a previous command?
o How do you recall fifth-most recent command?
o How do you get the line you are looking for if you over shoot?
5. Perform the following
o How do you Increase the size of your History to 20000? Hint: HISTSIZE
o How do you executes the previous to previous command
o Repeat the command with event number 33 and execute it
o Repeat the command with event number 33 with out executing it
6. Perform the following
o How do you search history list for previous commands. How do you repeat the se
arch? If you over shoot how do you come back
o Execute the command prior to the previous one
o How do you perform a substitution on the immediately previous command?
o List out the last 5 commands you used in your computer
o Repeat the last command beginning with v
o How do you perform substitution in recalled command ls
7. Perform the following
o How do you change or revert to your most recent previous directory?
o Which variable is used to store the last argument of the last command? Perform
it with an example.
o How do you display Event number in prompt?
o How do you display PWD in prompt?
o How do you display hostname of your computer in prompt?
8. Perform the following
o How do you list alias available in your shell?
o How do you incorporate positional parameters in an alias? Perform it on cd.
o How do you redefine and unset an alias? Perform it with an example.
9. How do you display all the current settings of the terminal?
10. How do you overwrite the protection feature noclobber?
11. Which file simply incinerates all output written to it and accepts any strea
m with out growing its size? Perform with an example
12. How a variable can also be assigned the value of another variable? Perform w
ith an example
13. How do you concatenate two shell variables? Perform with an example
14. Create a local variable in the parent shell then run a Bash sub-shell with s
h and check whether you can see the variable there or not
15. Using expr perform four basic arithmetic operations as well as the modulus
16. How to change echoe: Whether backspacing should erase the character using st
ty
17. How to change echo: Entering a password through a shell script using stty
Lab Cycle -3
Bash Shell Programs to practice
1. Write a Shell Program that tests whether or not an input string of size n is
a Palindrome (that is, reads the same backward and forward) are not.
2. Write a Shell Program using functions to find the square of first N numbers a
nd to calculate its sum
3. Write a Shell Program using functions to check whether the year is leap or no
t
4. Write a Shell Program using functions to calculate xn
5. Write a Shell Program to Implement
a. Recursive Factorial Algorithm using Exit Code
b. Recursive Factorial Algorithm using Standard Output
6. Write a Shell Program to Implement
a. Recursive Fibonnoci Series Algorithm
b. Iterative Fibonnoci SeriesAlgorithm
7. Write a Shell Program to Implement Euclid GCD Algorithm
8. Write a Shell Program to Implement Powers Recursive Algorithm
9. Write a Shell Program to Implement Recursive GCD Algorithm
10. Write a Shell Program to implement the iterative Insertion sort Recursive In
sertion Sort
11. Write a Shell Program to generate prime numbers
12. Write a Shell Program using functions to sort the given numbers
13. Write a Shell Program to Implement the Sieve of Eratosthenes Algorithm to ge
nerate prime numbers
14. Write a Shell Program to search an element using binary search method
15. Write a Shell Program to search an element using sequential (linear) search
method and to find the number of occurrences in the array
16. Write a Shell Program for a recursive function that outputs the maximum valu
e in a list of size n
17. Write a Shell Program to implement the Merge sort
18. Write a Shell program to implement Open-Address hash table for any given num
bers and perform the following operations HASH-DELETE, HASH-INSERT, HASH-SEARCH
19. Write a Shell Program to implement a push down Stack (Using Arrays)
20. Write a Shell Program to Implement the Towers of Hanoi recursively and itrat
ively
Sample: How to perform real number calculation in shell script and store result
to third variable , lets say a=5.66, b=8.67, c=a+b?
#!/bin/bash
# Q10
#
a=5.66
b=8.67
c=`echo $a + $b | bc`
echo "$a + $b = $c"