The tag has no usage guidance.

learn more… | top users | synonyms

8
votes
2answers
5k views

How to trigger error using Trap command

I am using Ubuntu 12.04.2. I am trying to use "trap" command to capture abnormal or error in my shell script but I am also trying to manually trigger "Error" exit. I have tried exit 1, but it won't ...
6
votes
4answers
440 views

How can I handle SIGINT trap with a user prompt in shell script?

I am trying to handle SIGINT/CTRL+C interrupt in such a way that if a user accidentally presses ctrl-c, he is prompted with a message, "Do you wish to quit?(y/n)". If he enters yes, then exit the ...
27
votes
10answers
70k views

How to stop the loop bash script in terminal?

For example, #!/bin/bash while : do sl done How to terminate this bash script?
7
votes
3answers
3k views

Silently start task in background

I know that you can use this to start a process in the background, without getting the notification when the process is put in the background and when it is done like so: (command &) &> /dev/null ...
7
votes
1answer
86 views

Standard subshell vs command-substitution subshell

Please explain these trap outputs: $ line(){ echo -------------; echo $BASHPID; } $ trap 'echo bye' EXIT; trap -p; line; (trap -p; line); echo "$(trap -p; line)" trap -- 'echo bye' EXIT trap -- '' ...
7
votes
3answers
6k views

What is signal 0 in a trap command?

I'm following this guide on how to set up passwordless SSH authentication with ssh-agent. To start up ssh-agent the author recommends the following code in .bash_profile: SSHAGENT=/usr/bin/ssh-agent ...
1
vote
2answers
2k views

how to trap a suspend a resume from a bash script

I have a bash script (on osx) running continuously, it currently traps and handles a terminate like so trap onshutdown TERM how can I make trap also handle suspend/resume like trap onsuspend ? ...
6
votes
2answers
1k views

Getting wrong $LINENO for a trapped function

I am writing a Bash script for myself to learn scripting. At some point, I need to add trap in order to clean unwanted directories and files if script is killed. However, for some reason I do not ...