microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.76k stars 29.1k forks source link

Terminal Shell Integration Error -- bash: eval: line 5: unexpected token `EOF' in conditional command #157189

Closed branic closed 2 years ago

branic commented 2 years ago

Type: Bug

With Terminal Shell Integration enabled opening a terminal results in the below error being reported in the shell window:

bash: eval: line 141: unexpected token `EOF' in conditional command
bash: eval: line 141: syntax error: unexpected end of file

A very similar error is reported everytime a command is executed (or the enter key is pressed):

bash: eval: line 5: unexpected token `EOF' in conditional command
bash: eval: line 5: syntax error: unexpected end of file

Enabling set -x and hitting enter in the terminal shows this output:

+++ __vsc_preexec_all -x
+++ '[' 0 = 0 ']'
+++ __vsc_in_command_execution=1
+++ builtin eval '[['
bash: eval: line 5: unexpected token `EOF' in conditional command
bash: eval: line 5: syntax error: unexpected end of file
+++ __vsc_preexec
+++ __vsc_initialized=1
.... TRUNCATED ....

Looking at /usr/share/code/resources/app/out/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh reveals that the command (line 127) causing the error is:

__vsc_dbg_trap="$(trap -p DEBUG | cut -d' ' -f3 | tr -d \')"

which is called by the command (line 140):

builtin eval ${__vsc_dbg_trap}

Running echo ${__vsc_dbg_trap} in the integrated terminal returns (minus the bash eval errors):

[[

When I execute the trap -p DEBUG command (from line 127) in another bash shell (outside of VSCode) the result is:

trap -- '[[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && chruby_auto' DEBUG

and running the full trap -p DEBUG | cut -d' ' -f3 | tr -d \' command (from line 127) returns:

[[

This did not occur prior to version 1.70.0 even with the Shell Integration setting enabled.

VS Code version: Code 1.70.0 (da76f93349a72022ca4670c1b84860304616aaa2, 2022-08-04T04:38:48.541Z) OS version: Linux x64 5.18.15-200.fc36.x86_64 Modes:

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz (12 x 2700)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: disabled_software
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled| |Load (avg)|2, 1, 1| |Memory (System)|62.56GB (49.15GB free)| |Process Argv|--unity-launch --crash-reporter-id 57fdd0a5-4103-4bed-9134-70c1dcd69cc9| |Screen Reader|no| |VM|0%| |DESKTOP_SESSION|gnome-xorg| |XDG_CURRENT_DESKTOP|GNOME| |XDG_SESSION_DESKTOP|gnome-xorg| |XDG_SESSION_TYPE|x11|
Extensions (38) Extension|Author (truncated)|Version ---|---|--- asciidoctor-vscode|asc|2.9.8 scratchpads|bue|0.0.7 solargraph|cas|0.23.0 vscode-markdownlint|Dav|0.47.0 ansible-vault|dho|0.1.3 docs-markdown|doc|0.2.113 githistory|don|0.6.19 gitlens|eam|12.1.2 json-tools|eri|1.0.2 opensslutils|ffa|1.1.1 shell-format|fox|7.2.2 gc-excelviewer|Gra|4.2.55 todo-tree|Gru|0.0.215 rest-client|hum|0.25.0 vscode-jmespath|jos|0.0.6 bash-ide-vscode|mad|1.14.0 git-graph|mhu|1.30.0 vscode-docker|ms-|1.22.1 python|ms-|2022.12.0 vscode-pylance|ms-|2022.8.10 remote-containers|ms-|0.241.3 remote-ssh|ms-|0.84.0 remote-ssh-edit|ms-|0.80.0 cpptools|ms-|1.11.4 ruby|reb|0.28.1 ansible|red|0.11.12 vscode-commons|red|0.0.6 vscode-yaml|red|1.9.1 bash-debug|rog|0.3.9 rufo-vscode|sil|0.0.3 code-spell-checker|str|2.3.4 shellcheck|tim|0.19.6 pdf|tom|1.2.0 vscode-icons|vsc|11.14.0 vim|vsc|1.23.2 jinja|who|0.0.8 vscode-ruby|win|0.28.0 markdown-all-in-one|yzh|3.4.3 (2 theme extensions excluded)
A/B Experiments ``` vsliv368cf:30146710 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 pythonvspyl392:30443607 vserr242cf:30382550 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vshan820:30294714 vstes263cf:30335440 vscorecescf:30445987 pythondataviewer:30285071 vscod805:30301674 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593cf:30376535 vsc1dst:30438360 pythonvs932:30410667 wslgetstarted:30449410 vscscmwlcmt:30465135 cppdebug:30492333 vscaat:30438848 pylanb8912cf:30529770 vsclangdf:30486550 c4g48928:30535728 dsvsc012cf:30540253 ```
Tyriar commented 2 years ago

@branic can you provide what version of bash you're using with bash --version?

branic commented 2 years ago

@Tyriar Here you go.

GNU bash, version 5.1.16(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Also, in case it helps, I'm running Fedora 36 Workstation.

Tyriar commented 2 years ago

@branic thanks, could you also provide the output of trap -p DEBUG?

branic commented 2 years ago

From within the integrated terminal (with shell integration enabled):

trap -- '__vsc_preexec_all "$_"' DEBUG

From within the integrated terminal (with shell integration disabled):

trap -- '[[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && chruby_auto' DEBUG
Tyriar commented 2 years ago

trap -- '[[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && chruby_auto' DEBUG

This seems like an odd trap, $BASH_COMMAND refers to the command that was just run, whereas $PROMPT_COMMAND refers to the command that is run to generate the prompt, they seem unrelated to me so I'm not sure what benefit this condition adds? Did you add that yourself or did it come with Fedora?

Tyriar commented 2 years ago

I can reproduce the issue by adding this to my .bashrc:

trap "[[ \"A\" != \"B\" ]] && echo trap" DEBUG
branic commented 2 years ago

trap -- '[[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && chruby_auto' DEBUG

That trap command is coming from chruby which is used for managing different Ruby versions. The code adding it can be found at https://github.com/postmodern/chruby/blob/613a4834049e4d8de52de764213182a59c214ce1/share/chruby/auto.sh#L32.

Tyriar commented 2 years ago

Perfect, thanks for all the info it was super helpful!

meganrogge commented 2 years ago

@Tyriar reverting to this https://github.com/microsoft/vscode/commit/19ae5645f9fe8bfefd73eaac42f6f7f1442acc73 fixes it

ivan-pua commented 2 years ago

FYI I'm using a Mac (Version 12.5) with chruby installed and I have the same issue.

RyanSadowski0 commented 2 years ago

I've also been seeing this on OSX after install chruby.

meganrogge commented 2 years ago

/closedWith https://github.com/microsoft/vscode/pull/157552

vscodenpa commented 2 years ago

Issue marked as unreleased but unable to locate closing commit in issue timeline. You can manually reference a commit by commenting \closedWith someCommitSha, or directly add the insiders-released label if you know this has already been releaased

Tyriar commented 2 years ago

/closedWith 07b2f3b

vscodenpa commented 2 years ago

Issue marked as unreleased but unable to locate closing commit in repo history. If this was closed in a separate repo you can add the insiders-released label directly, or comment \closedWith someShaThatWillbeReleasedWhenThisIsRelesed.

meganrogge commented 2 years ago

/closedWith 5acb2a86c5230dd385e0aa383c118db61bc8de10

jazzlw commented 2 years ago

I had this same issue, and just updated. The original issue is gone, but now I get another bash error: bash: [[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && chruby_auto: command not found

Using set -x to see what's running yields:

+++ __vsc_preexec_all clear
+++ '[' 0 = 0 ']'
+++ __vsc_in_command_execution=1
+++ builtin eval ''\''[[' '"$BASH_COMMAND"' '!=' '"$PROMPT_COMMAND"' ']]' '&&' 'chruby_auto'\'''
++++ '[[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && chruby_auto'
bash: [[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && chruby_auto: command not found
+++ __vsc_preexec
+++ __vsc_initialized=1
+++ [[ ! __vsc_prompt_cmd =~ ^__vsc_prompt* ]]
+++ __vsc_current_command=
+++ __vsc_command_output_start
+++ builtin printf '\033]633;C\007'
+++ builtin printf '\033]633;E;%s\007' ''
++ __vsc_prompt_cmd
++ __vsc_status=0
++ __vsc_precmd
++ __vsc_command_complete 0
++ '[' '' = '' ']'
++ builtin printf '\033]633;D\007'
++ __vsc_update_cwd
++ builtin printf '\033]633;P;Cwd=%s\007' /Users/jazzlw/src/ROS_ws/projector_driver
++ __vsc_current_command=
++ __vsc_update_prompt
++ '[' 1 = 1 ']'
++ [[ \[\](py38) \[\]\h:\W \u\$ \[\]\[\] == '' ]]
++ [[ \[\](py38) \[\]\h:\W \u\$ \[\]\[\] != \\\[\]\6\3\3\;\A\\\\]\(\p\y\3\8\)\ \\\[\]\6\3\3\;\A\\\\]\\\h\:\\\W\ \\\u\\\$\ \\\[\]\6\3\3\;\B\\\\]\\\[\]\6\3\3\;\B\\\\] ]]
++ [[ \[\]> \[\] == '' ]]
++ [[ \[\]> \[\] != \\\[\]\6\3\3\;\F\\\\]\>\ \\\[\]\6\3\3\;\G\\\\] ]]
++ __vsc_in_command_execution=0

@meganrogge should I make a new issue for this?

meganrogge commented 2 years ago

does running chruby_auto in your terminal produce the same error?

branic commented 2 years ago

@jazzlw I think you are hitting what was reported in #157851 and fixed in #158124

++++ '[[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && chruby_auto'

That is the line that is trying to be run and it has the ' around it so bash thinks it is a single string and doesn't parse it. Which results in the error:

bash: [[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && chruby_auto: command not found

jazzlw commented 2 years ago

@meganrogge chruby_auto works fine in native terminal. I think what @branic said above was correct and another update has resolved the problem! Thanks!