Thursday, September 13, 2012

$IGNOREEOF vs ignoreeof

How to prevent your terminal from getting closed OR prevent from getting the user logged out on pressing Control-D?
  The answer to this is IGNOREEOF / ignoreeof. Let us see what is this IGNOREEOF and the difference between IGNOREEOF and ignoreeof.

   Many of the times we might have pressed some key only to realize that the terminal got closed or he got logged out from his account. The user gets logged out whenever an EOF character is pressed which is Control-D.  So, if the user happens to be in his login shell, then logically the Ctrl-D ends up in getting the user's terminal closed as well.

Bash/Bourne shell:
    In Bash/Bourne shell, the log-out from the user account can be prevented by using the environment variable IGNOREEOF.
export IGNOREEOF=2
    The env variable IGNOREEOF is set to 2. This means, the shell will neglect 'Ctrl-D' key 2 times. A warning message will be displayed to the user on pressing Control-D for 2 times, however on the 3rd time, the user will be logged out. So, the user can set a value of his choice. In this way, the user can prevent himself from getting logged out of the shell. It is ideal to put this setting in the profile file to make it permanent.
  By just declaring the environment variable without any value, the shell will neglect Ctrl-D 10 times since 10 is the default value.

  To unset the variable IGNOREEOF:
  The environment variable IGNOREEOF does not work for k-shell. Instead, it is done using one of the k-shell set command options, "ignoreeof". This is the difference between IGNOREEOF and ignoreeof.
To set the 'ignoreeof' option in ksh:
set -o ignoreeof
   This means ignoreeof is set. Once set, the shell will neglect Ctrl-D for 20 times in case of a ksh93, 11 times in case of older ksh shells which are the default values. A user defined value cannot be set in ksh unlike the IGNOREEOF in bash shell.

  To unset the ignoreeof in ksh:
set +o ignoreeof
Note: ignoreeof works in bash and bourne shells as well.

No comments:

Post a Comment