Imported from ../bash-3.1.tar.gz.
[platform/upstream/bash.git] / builtins / trap.def
index 9dd746f..669bea7 100644 (file)
@@ -1,7 +1,7 @@
 This file is trap.def, from which is created trap.c.
 It implements the builtin "trap" in Bash.
 
-Copyright (C) 1987-2004 Free Software Foundation, Inc.
+Copyright (C) 1987-2005 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -23,7 +23,7 @@ $PRODUCES trap.c
 
 $BUILTIN trap
 $FUNCTION trap_builtin
-$SHORT_DOC trap [-lp] [[arg] signal_spec ...]
+$SHORT_DOC trap [-lp] [arg signal_spec ...]
 The command ARG is to be read and executed when the shell receives
 signal(s) SIGNAL_SPEC.  If ARG is absent (and a single SIGNAL_SPEC
 is supplied) or `-', each specified signal is reset to its original
@@ -87,7 +87,7 @@ int
 trap_builtin (list)
      WORD_LIST *list;
 {
-  int list_signal_names, display, result, opt;
+  int list_signal_names, display, result, opt, first_signal;
 
   list_signal_names = display = 0;
   result = EXECUTION_SUCCESS;
@@ -118,14 +118,19 @@ trap_builtin (list)
   else
     {
       char *first_arg;
-      int operation, sig;
+      int operation, sig, first_signal;
 
       operation = SET;
       first_arg = list->word->word;
+      first_signal = first_arg && *first_arg && all_digits (first_arg) && signal_object_p (first_arg, opt);
+
+      /* Backwards compatibility */
+      if (first_signal)
+       operation = REVERT;
       /* When in posix mode, the historical behavior of looking for a
         missing first argument is disabled.  To revert to the original
         signal handling disposition, use `-' as the first argument. */
-      if (posixly_correct == 0 && first_arg && *first_arg &&
+      else if (posixly_correct == 0 && first_arg && *first_arg &&
                (*first_arg != '-' || first_arg[1]) &&
                signal_object_p (first_arg, opt) && list->next == 0)
        operation = REVERT;
@@ -209,7 +214,6 @@ showtrap (i)
   char *t, *p, *sn;
 
   p = trap_list[i];
-
   if (p == (char *)DEFAULT_SIG)
     return;