Anonymous | Login | 2023-12-07 11:16 UTC |
Main | My View | View Issues | Change Log | Docs |
Viewing Issue Simple Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||
ID | Category | Severity | Type | Date Submitted | Last Update | ||
0000163 | [1003.1(2008)/Issue 7] Shell and Utilities | Editorial | Error | 2009-10-08 15:28 | 2013-04-16 13:06 | ||
Reporter | msbrown | View Status | public | ||||
Assigned To | ajosey | ||||||
Priority | normal | Resolution | Accepted As Marked | ||||
Status | Closed | ||||||
Name | Mark Brown | ||||||
Organization | IBM | ||||||
User Reference | |||||||
Section | 2.14 trap | ||||||
Page Number | 2369-2370 | ||||||
Line Number | 74930-74934 | ||||||
Interp Status | --- | ||||||
Final Accepted Text | Note: 0000252 | ||||||
Summary | 0000163: Problems in rationale of trap shell builtin | ||||||
Description |
SUSv4> Set a trap so the logout utility in the directory referred SUSv4> to by the HOME environment variable executes when the shell SUSv4> terminates: SUSv4> SUSv4> trap '$HOME/logout' EXIT That should be: trap '"$HOME/logout"' EXIT trap '~/logout' EXIT ($HOME expanded on exit) or: trap "$HOME/logout" EXIT trap ~/logout EXIT ($HOME expanded upon evaluation of that trap command). Later on: SUSv4> The command: SUSv4> SUSv4> trap '$cmd' 0 SUSv4> SUSv4> causes the contents of the shell variable cmd to be SUSv4> executed as a command when the shell exits. Using SUSv4> double-quotes instead of single-quotes might have SUSv4> unexpected behavior, since in theory the value of cmd SUSv4> might be a decimal integer which would be treated as SUSv4> a condition, not an action; or cmd might begin with SUSv4> '-' . I find that misleading at best. trap "$cmd" 0 (or trap ";$cmd" 0 if you want to account for possible $cmd's that start with "-" or are decimal numbers which would be quite odd) ($cmd meant to be shell code to be executed on exit) trap '"$cmd"' 0 ($cmd being the name of a command to be executed) trap 'eval -- "$cmd"' 0 ($cmd meant to be shell code to be executed on exit, but this time $cmd is expanded upon the action execution). all make sense to me. But trap '$cmd' 0 doesn't For instance, in; cmd='echo "* exit now *" >&2' trap '$cmd' 0 assuming that $IFS has been unchanged upon exit would output the list of filenames in the current directory that start with a double-quote, followed by "exit now" followed by the filenames that end with a double-quote (or *" if there's none), followed by ">&2". atexit='echo bye >&2' trap "$atexit" 0 or: atexit='echo bye >&2' trap 'eval "$atexit" 0' ... atexit='echo ciao >&2' ... (though in that case, I'd prefer: atexit() { echo bye >&2; } trap atexit 0 ... atexit() { echo ciao >&2; } ) make more sense. SUSv4> Also, using double-quotes will cause the value SUSv4> of cmd to be expanded twice, once when trap is SUSv4> executed, and once when the condition arises. Well no, it will be expanded upon evaluating the trap command, and that expanded content will be evaluated upon exit, which is quite the behavior I would expect. |
||||||
Desired Action |
change trap '$HOME/logout' EXIT to be trap '"$HOME/logout"' EXIT ($HOME expanded on exit) or: trap "$HOME/logout" EXIT ($HOME expanded upon evaluation of that trap command). |
||||||
Tags | tc1-2008 | ||||||
Attached Files | |||||||
|
![]() |
|||||||||||||
|
![]() |
|||
Date Modified | Username | Field | Change |
2009-10-08 15:28 | msbrown | New Issue | |
2009-10-08 15:28 | msbrown | Status | New => Under Review |
2009-10-08 15:28 | msbrown | Assigned To | => ajosey |
2009-10-08 15:28 | msbrown | Name | => Mark Brown |
2009-10-08 15:28 | msbrown | Organization | => IBM |
2009-10-08 15:28 | msbrown | Section | => 2.14 trap |
2009-10-08 15:28 | msbrown | Page Number | => 2369-2370 |
2009-10-08 15:28 | msbrown | Line Number | => 74930-74934 |
2009-10-08 15:28 | msbrown | Interp Status | => --- |
2009-10-08 15:32 | msbrown | Desired Action Updated | |
2009-10-08 15:33 | msbrown | Desired Action Updated | |
2009-10-09 09:46 | geoffclare | Note Added: 0000252 | |
2009-10-15 15:34 | msbrown | Final Accepted Text | => Note: 0000252 |
2009-10-15 15:34 | msbrown | Status | Under Review => Resolved |
2009-10-15 15:34 | msbrown | Resolution | Open => Accepted As Marked |
2010-08-27 13:07 | ajosey | Tag Attached: tc1-2008 | |
2010-09-07 11:39 | geoffclare | Note Added: 0000542 | |
2010-09-07 11:39 | geoffclare | Status | Resolved => Under Review |
2010-09-07 11:39 | geoffclare | Resolution | Accepted As Marked => Reopened |
2010-09-09 16:04 | geoffclare | Note Edited: 0000252 | |
2010-09-09 16:04 | geoffclare | Note Deleted: 0000542 | |
2010-09-09 16:05 | geoffclare | Status | Under Review => Resolved |
2010-09-09 16:05 | geoffclare | Resolution | Reopened => Accepted As Marked |
2013-04-16 13:06 | ajosey | Status | Resolved => Closed |
2016-02-23 21:36 | eblake | Relationship added | related to 0000252 |
2021-11-04 15:28 | eblake | Relationship added | related to 0001440 |
Mantis 1.1.6[^] Copyright © 2000 - 2008 Mantis Group |