Find the answer to your Linux question:
Results 1 to 4 of 4
I am a beginner in scripting and following is written on the top of my script trap "" HUP Can an one help me in understanding this? Thanks...
  1. #1
    Linux Newbie
    Join Date
    Jan 2008
    Posts
    114

    meaning of trap "" HUP

    I am a beginner in scripting and following is written on the top of my script

    trap "" HUP
    Can an one help me in understanding this?

    Thanks

  2. #2
    Linux Newbie
    Join Date
    Jan 2008
    Location
    UK
    Posts
    211
    trap is a builtin command used for specifying the actions to take on receipt of signals.
    so:
    trap HUP means Hang up; usually sent when a terminal goes off line, or a user logs out.

    Hope this helps.

  3. #3
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    This means "In this script, ignore the hangup signal."

    For an introduction to signals, and a list of signals, see this.

    You could also have spelled this as
    Code:
    trap "" SIGHUP
    bash scripts normally stop running and emit "Hangup" to the screen and stop running when they receive a hangup signal. The statement you asked about causes this signal to be ignored. You can put something between the quotes if you wish; that will be a bash statement to execute upon receiving the hangup signal. It can be as simple as printing the content of some variables, or it can be the invocation of some other script, or it can be almost anything.

    In addition to signals, you can also say things like
    Code:
    trap "somethingsomething" EXIT
    to run some command upon exit from your script.

    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  4. #4
    Linux Newbie
    Join Date
    Jan 2008
    Posts
    114
    Thanks, now understood

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...