Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Bash by VEG 65 ( 9 years ago )
1. Display the Primary and Secondary prompt. Change the primary prompt to your name: temporarily

2:  As soon as you login, the prompt should be changed to your name: also the name of the home directory should be automatically displayed.

3: Check the content of the Environmental variable SHELL.

4: Try the below exercise and check the output.


Note: Type every line and press enter, do not type the entire code in a vi editor.

  $continent=”Africa”
  $echo “$continent”
   ------------? Africa
  $sh
  $echo “$continent”
   ------------? No Response
  $continent=”Asia”
  $echo “$continent”
   ------------? Asia
     $ctrl + d
  $echo “$continent”
   ------------? Africa
  $sh
  $echo “$continent”
   ------------? No Response
     $ctrl + d

5: Try the below exercise and check the output. (Export variables)

Note: Type every line and press enter, do not type the entire code in a vi editor.

 $continent=”Africa”
 export continent
 $echo “$continent”
  ------------? Africa
 $sh
 $echo “$continent”
  ------------? Africa
 $continent=”Asia”
 $echo “$continent”
  ------------? Asia
 $ctrl + d
 $echo “$continent”
  ------------? Africa

  
6: Write a shell script that takes the user name as input and reports whether he / she has logged in or not.



7: Write a shell script to display the file name and its contents of all the files that is there in the current directory.

 more * | cat
 
8: Write a shell script, which will take a file name as argument and check whether the file exists and display its access permissions for user.

   file.sh
   if [ -e "$1" ]
   then
     echo "$1 File Found"
   else
     echo "$1 File not found"
   fi

9: Pass three numbers as command line arguments and display the largest number in the given three numbers.

10: Write a shell script which will accept a pattern and a file name. The pattern will be searched in the file provided. Display appropriate messages and perform necessary validations on file.

11: To create a menu program for a) creating a file, b) Creating a  directory, c) copying a file, d) moving a file. (use functions)
a. If the file exists already give the appropriate message
b. If the dir exists already give the appropriate error message
c. Source file should exist if not give a message, It should have read permission if not another message, Destination file either there or not, 
 if not there then create it and copy it. 
 If there, then ask whether to overwrite or not, 
 if yes then overwrite it or else give a message file exists already and not overwritten.

12: Write a function yesno() to display question to user and accept answer as y/n. If answer to the question is y the function should return 0 otherwise 1.
      Use yesno functions for asking different questions. Question will be passed as   parameter to the function.
       Accept filename from user check whether it is file or directory. Use yesno() function to display question do you really want to delete file? If the ans is y, then delete the file or directory.

13: Write a shell script to store names of four employees and check whether those employees are currently logged in or not. Display appropriate message.


14: Accept the users first and last name and the echo the entire name along with some suitable comment.
  
  #fl.sh
  echo "Enter first name"
  read fname
  echo "Enter last name"
  read lname
  echo "Your name is$fname $lname"

15: List all files that have been modified today.

 find . -mtime -1 -print

 
16: Display long listing of only the regular files in the current directory.

  ls -p -l | grep -v /

17: Display details of all files in the 2 “paths” accepted from user. The display should be screen by screen.

  echo "Enter First Path"
  read path1
  echo "Enter Second Path"
  read path2

  echo "-----------Path 1 Files-----------------------"
  ls $path1
  echo "-----------Path 2 Files-----------------------"
  ls $path2



18: Let the script display its name and its PID.

 echo "The script name is $0"
 echo "The script pid is $$"


19: Get the concatenated o/p of 2 files into a third file: Take 3 command line arguments: The first argument is the name of a destination file, 
 and the other two arguments are names of files whose contents are to be placed in the destination file.
 
 cat "$2 $3 > $1"


Stretched Assignments:

20: Write a menu driven shell program to:
a.   Display calendar of current month
b. Search for a pattern in all the files/subdirectories from current directory.  
c. Count the no. of directories / sub directories in current directory

21: Display day of week for a given date. (ddmmyyyy) 
           If day is Monday, display message  “Monday Blues”
                         Friday display message “yeh! It’s week end.”
           Similarly display different messages for each day of the week. 

22: Display the contents of all .lst files in the current directory.

23: Design a simple calculator, which will add/subtract/multiply/divide 2 numbers.
eg.   cal 10 20 +   will give o/p as 30.

24: For a student file with the following fields, rollno, name, marks, Generate 2 files ‘Pass’ and ‘Fail’ containing records of student who have passed or failed. Also count the number of students who have passed or failed.

25: Accept a date string from terminal and display employees born after the input date.

 

Revise this Paste

Your Name: Code Language: