Question

In: Computer Science

Design a shell program to remove all the shell programming files ending with sh on your...

Design a shell program to remove all the shell programming files ending with sh on your home directory when a SIGINT signal is received.


Solutions

Expert Solution

I understand the problem, But dosent specified, from where do you get the SIGINT signal. So what I had done is to generate a SIGINT signal in the program (press ctrl+c) for that.

We can ignore the SIGINT with the command

trap '' SIGINT

To do something when a SIGINT command has occured , handle it with the command

trap handler SIGINT

and the function

handler()
{
        echo "Do something here"
        
}

So to answer the question completely


handler()
{
        echo "Removing all the bash script in home dir.... :"
        rm -r ~/*.sh
        echo "Removed all the bash script in home dir :"
}
while read -p  "enter (ctrl+c) for SIGINT : " temporaryVariable 
do
        echo "you entered : $temporaryVariable" 
        trap handler SIGINT
done 

save theis script anywhere other than the home directory(becase we need to remove all the sh files in home)

Explenations :

I had created three bash scripts in the home directory

Screenshot of the ls command (which list the .sh files)

Now I had placed the script in another directory and run it

screenshot the running of program

( make sure that you enter first an alphebet , only enter teh ctrl + c in next iteratioon)

I entered ctrl+c to generate the SIGINT

and ctrl+z to stop the execution of the script

Now I will again show the screenshot of the home directory

The highlighted output is the result of the command ls *.sh after executing the bash script.

-----------------------------------------------------------


Related Solutions

Write a shell script (to run on the Bourne shell) called cp2.sh to copy all the...
Write a shell script (to run on the Bourne shell) called cp2.sh to copy all the files from two named directories into a new third directory. Timestamps must be preserved while copying files from one directory into another. Task Requirements Three directory names must be supplied as arguments to your script when it is executed by the user. In the beginning of your script you need to check that the first two directory names provided (e.g. dir1 and dir2) exist...
Write a program to remove extra blanks from text files. Your program should replace any string...
Write a program to remove extra blanks from text files. Your program should replace any string of two or more blanks with one single blank. It should work as follows: * Create a temporary file. * Copy from the input file to the temporary file, but do not copy extra blanks. * Copy the contents of the temporary file back into the original file. * Remove the temporary file. Your temporary file must have a different name than any existing...
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given...
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given only two integer numbers from command line arguments and computing their multiplication. If two integer numbers are not given, print “Wrong Input” on your screen. Note that, the number of arguments is known when the script runs. Take a screenshot showing your shell program and its execution step. Design a shell program to remove all the shell programming files ending with sh on your...
Write a program, using your favourite programming language, to parse time log files to report how...
Write a program, using your favourite programming language, to parse time log files to report how much time in total spent on project. The time log file TimeLogCarbon.txt. Time Log: 2/23/12: 9:10pm - 11:40pm getting familiar with Flash 2/29/12: 12:50pm - 2:00pm getting familiar with Flash 3/1/12: 6:00pm - 11:40pm getting familiar with Flash 3/3/12: 3:00pm - 7:00pm step-debug Energy Game code 3/4/12: 8:00pm - 11:40pm start carbon game 3/5/12: 2:00pm - 3:00pm, 4:00pm - 4:30pm carbon game 3/6/12: 11:30am...
In this programming assignment, you will implement a SimpleWebGet program for non- interactive download of files...
In this programming assignment, you will implement a SimpleWebGet program for non- interactive download of files from the Internet. This program is very similar to wget utility in Unix/Linux environment.The synopsis of SimpleWebGet is: java SimpleWebGet URL. The URL could be either a valid link on the Internet, e.g., www.asu.edu/index.html, or gaia.cs.umass.edu/wireshark-labs/alice.txt or an invalid link, e.g., www.asu.edu/inde.html. ww.asu.edu/inde.html. The output of SimpleWebGet for valid links should be the same as wget utility in Linux, except the progress line highlighted...
Write a shell program named HELLO2(this should be done in linux, using bash) Consider files in...
Write a shell program named HELLO2(this should be done in linux, using bash) Consider files in the current directory whose names end in 't' or 'z'. For such files only, your program should list certain LINES of the file(s). These lines are those that have at least 4 x's somewhere in the line. Note that the x's may be upper- or lower-case, and may be separated by other characters; so the following 3 lines DO match: XXxX and more things...
This is an exercise to design and write a Python program in good programming style for...
This is an exercise to design and write a Python program in good programming style for a simulation of stock price over a period of 100 days. In this exercise, you are asked to simulate the stock price starting at $100.00 for 100 days with a daily fluctuation based on the Normal Distribution with mean = 0.0 & sigma = 0.0125. The program will show the daily stock price, the 7-day minimum, the 7-day maximum, the 7-day average, and the...
Programming Projects Project 1—UNIX Shell This project consists of designing a C program to serve as...
Programming Projects Project 1—UNIX Shell This project consists of designing a C program to serve as a shell interface that accepts user commands and then executes each command in a separate process. Your implementation will support input and output redirection, as well as pipes as a form of IPC between a pair of commands. Completing this project will involve using the UNIX fork(), exec(), wait(), dup2(), and pipe() system calls and can be completed on any Linux, UNIX, or macOS...
In this assignment you will write your own shell program, Mav shell (msh), similar to bourne...
In this assignment you will write your own shell program, Mav shell (msh), similar to bourne shell (bash), c-shell (csh), or korn shell (ksh). It will accept commands, fork a child process and execute those commands. The shell, like csh or bash, will run and accept commands until the user exits the shell. Your file must be named msh.c Functional Requirements Requirement 1: Your program will print out a prompt of msh> when it is ready to accept input. It...
Write a bash script to find all the files ending with .c recursively for every directory...
Write a bash script to find all the files ending with .c recursively for every directory in your current working directory, then copy each one to a folder called programs, need handle duplicates by appending the number to the end of the file (ex main.c main-1.c ) compile them and generate a report report should look like: main.c compiles prog2.c failed main-2.c compiles etc.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT