View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000099 | tcsh | General | public | 2019-08-13 14:44 | 2022-08-09 09:53 |
Reporter | xdelaruelle | Assigned To | christos | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | assigned | Resolution | open | ||
Product Version | 6.21.00 | ||||
Summary | 0000099: use of :q in back-tick context leads to erroneous extra history entries | ||||
Description | I am developing a tool called Modules (http://modules.sourceforge.net/) which enables to dynamically update user's shell environment. In short, this tool provides a shell alias called `module` which evaluates in the current shell the output of a script producing shell code. The `module` command is currently defined this way: $ alias module 'eval "`/usr/share/Modules/libexec/modulecmd.tcl tcsh \!*:q`"' Which leads to erroneous entries in the ~/.history file: #+1565705427 module load foo bar #+1565705427 load foo bar#+1565705430 history All arguments passed from the alias to the modulecmd.tcl script are added as a second history line. These erroneous entries seem to come from the use of the quote modifier `:q` within a back-tick context ``. Some explanation on the use of the quote modifier :q in this alias: as the modulecmd.tcl script outputs shell codes, it contains sometime special characters like curly braces, so the result of the script execution is enclosed in double quotes to pass it to eval. In this situation to correctly obtain quoted arguments, the quote modifier is used. The issue has been reproduced on tcsh versions 6.18, 6.19, 6.20 and 6.21. | ||||
Steps To Reproduce | To reproduce the issue on a small example, here is a script that produces some shell code (to define an alias or set an environment variable): $ cat ./dispatch #!/bin/csh if ( $#argv != 1 ) then echo echo should get exactly 1 arg exit 1 endif switch ( $argv[1] ) case myname: echo alias myname getent\\ passwd\\ \\\$USER\ \\\|\\ awk\\ -F:\\ \\\'\\\{print\ \\\$5\\\}\\\'; breaksw; case "": echo setenv EMPTY 1; breaksw; endsw $ echo $tcsh 6.21.00 Here we define the shell alias that calls the script and evaluates the shell code this script outputs: $ alias tuneenv 'eval "`./dispatch \!*:q`"' Then we use the alias: $ tuneenv "" $ echo $EMPTY 1 $ tuneenv myname $ myname Xavier $ exit Looking at history file, erroneous entries can be seen: $ tail ~/.history #+1565702553 tuneenv "" #+1565702553 ""#+1565702559 echo $EMPTY #+1565702565 tuneenv myname #+1565702565 myname#+1565702567 myname | ||||
Additional Information | Some additional tests to demonstrate the need to enclose script result in double quotes to pass it to eval: $ alias tuneenv 'eval `./dispatch \!*`' $ tuneenv myname Missing '}'. So without the double quotes, the shell alias myname which contains curly braces cannot be set Then if we enclose script result in double quotes, !* should get the quote modifier applied to correctly transmit quoted arguments: $ alias tuneenv 'eval "`./dispatch \!*`"' $ tuneenv myname $ myname Xavier $ tuneenv "" should get exactly 1 arg Without :q, the "" argument is not transmitted to the dispatch script. | ||||
Tags | No tags attached. | ||||
|
dispatch (279 bytes)
#!/bin/csh if ( $#argv != 1 ) then echo echo should get exactly 1 arg exit 1 endif switch ( $argv[1] ) case myname: echo alias myname getent\\ passwd\\ \\\$USER\ \\\|\\ awk\\ -F:\\ \\\'\\\{print\ \\\$5\\\}\\\'; breaksw; case "": echo setenv EMPTY 1; breaksw; endsw |
|
Sorry, I can't reproduce it with 6.21.00 on either Linux or NetBSD. Did that break with 6.21.00 or the bug was always there? |
|
I get the exact same result whether I test this on tcsh version 6.18, 6.19, 6.20 and 6.21 on a Linux system. Here are the details of the tcsh 6.21.00 ran: $ echo $version tcsh 6.21.00 (Astron) 2019-05-08 (x86_64-unknown-linux) options wide,nls,dl,al,kan,sm,rh,color,filec With that shell, applying code sequence described in 'Steps To Reproduce' section with dispatch script attached to this ticket (shebang adapted to match the tcsh shell ran), the same erroneous ~/.history file is obtained (as described in section). |
Date Modified | Username | Field | Change |
---|---|---|---|
2019-08-13 14:44 | xdelaruelle | New Issue | |
2019-08-13 14:44 | xdelaruelle | File Added: dispatch | |
2019-10-19 18:46 | christos | Assigned To | => christos |
2019-10-19 18:46 | christos | Status | new => assigned |
2019-10-19 18:54 | christos | Status | assigned => feedback |
2019-10-19 18:54 | christos | Note Added: 0003317 | |
2019-10-20 15:21 | xdelaruelle | Note Added: 0003318 | |
2019-10-20 15:21 | xdelaruelle | Status | feedback => assigned |