Bug 361835

Summary: Environment variables inside command line <-e> option are expanded even when they must not
Product: [Applications] konsole Reporter: Egor <egor.skriptunoff>
Component: generalAssignee: Konsole Developer <konsole-devel>
Status: CONFIRMED ---    
Severity: normal CC: martin.sandsmark
Priority: NOR    
Version: master   
Target Milestone: ---   
Platform: Mint (Ubuntu based)   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Egor 2016-04-15 20:02:19 UTC
Any $VAR in command line after <-e> option gets replaced with its value despite of enclosing with single quotes

Reproducible: Always

Steps to Reproduce:
$ konsole -e bash -c 'echo $SHELL;echo '\''$SHELL'\'';read'

Actual Results:  
/bin/bash
/bin/bash

Expected Results:  
/bin/bash
$SHELL

1. Lets consider the following command:
echo $SHELL;echo '$SHELL';read
It prints two lines: expanded and non-expanded $SHELL
First line of output: /bin/bash
Second line of output: $SHELL

2.  Wrap the command from step #1 with single quotes:
'echo $SHELL;echo '\''$SHELL'\'';read'

3. Append <bash -c> to the string from step #2:
bash -c 'echo $SHELL;echo '\''$SHELL'\'';read'
This command does exactly the same as command from step #1.

4. Use some other terminal emulator (for example, xterm) to use command from step #3 as argument for <-e> option:
xterm -e bash -c 'echo $SHELL;echo '\''$SHELL'\'';read'
It works as expected: it prints expanded $SHELL and non-expanded $SHELL:
/bin/bash
$SHELL

5. Now test the command from step #3 with <-e> option using konsole:
konsole -e bash -c 'echo $SHELL;echo '\''$SHELL'\'';read'
It prints:
/bin/bash
/bin/bash
konsole seems to always expand environment variables in <-e command args>.
This behavior looks like a bug.
Comment 1 Kurt Hindenburg 2016-05-21 16:56:49 UTC
I would agree it is a bug
Comment 2 Martin Sandsmark 2016-06-11 15:40:45 UTC
I think the unit test committed in 595adcd7e95ac050a4346b526164f791050691a7 is incorrect, "$SHELL" should still be expanded, but '$SHELL' should not?
Comment 3 Kurt Hindenburg 2016-06-11 15:45:59 UTC
echo $SHELL;echo '\''$SHELL'\''

The first should be expanded, the 2nd not, correct?
Comment 4 Martin Sandsmark 2016-06-11 15:58:53 UTC
the second example is missing a '?

but the test now tests basically «echo "$SHELL"», if I understand correctly, and that should be expanded, but «echo "$SHELL"» should not.
Comment 5 Kurt Hindenburg 2024-03-27 23:39:40 UTC
Still relevant today.