5

I upgraded to Linux Mint 21 (based on Ubuntu 22), having number of small issues, one of which is in VS Code, not in Terminal (gnome-terminal), running ls alias:

bash: printf: `Y': invalid format character

While I have defined these aliases:

# Base `ls` alias contains:
# - escape for it could be defined already
# - use colors when appropriate
# - group directories first
# - date format YYYY-Mmm-DD
alias ls="\ls --color=auto --group-directories-first --time-style=+'%Y-%b-%d'"

I did not notice this behavior in Focal, maybe I just look for errors now, or is this truly some error (mine, whoever)?

Notes:

https://www.gnu.org/software/coreutils/manual/html_node/Date-conversion-specifiers.html


$ type -a ls
ls is aliased to `\ls --color=auto --group-directories-first --time-style=+'%Y-%b-%d''
ls is /usr/bin/ls
ls is /bin/ls

Both in Terminal and VS Code.

printf %q\\n "PS1=$PS1" "PS2=$PS2" "PS3=$PS3" "PS4=$PS4" "PROMPT_COMMAND=$PROMPT_COMMAND"
PS1=\\\[\\e\]0\;\ \\w\ \\a\\\]\\\[\$color_green\\\]\\\$\ \\\[\$color_reset\\\]
PS2=\>\ 
PS3=
PS4=+\ 
PROMPT_COMMAND=

Only in VS Code (nothing in Terminal):

trap -p DEBUG
trap -- '__vsc_preexec_only "$_"' DEBUG
5
  • So it's not the prompt. Another related possibility would be a debug trap: what's the output of trap -p DEBUG ? And do you see the expected output from ls or not (actually, I think depending on the configuration the command might not be executed if the DEBUG trap fails, so that would still be consistent)? Aug 7 at 9:03
  • @Gilles'SO-stopbeingevil' You just hit something, have no idea what it is though... Aug 7 at 9:36
  • 4
    That vscode bug was fixed 2 days ago, but that code is still very buggy. Looks like they need to read When is double-quoting necessary? and Why is printf better than echo? at least). Aug 7 at 10:17
  • 3
    and instead of fixing it to use printf "... %s ..." "$__vsc_current_command", they've added a call to sed to escape the % signs. Sigh. Well, at least someone has noted that in the bug report. (Also it doesn't look like __vsc_preexec_only uses the argument it gets anyway, hmm)
    – ilkkachu
    Aug 7 at 10:21
  • The initial version of this question included a screenshot (image) showing the error occurring.  While we dislike images of text, the correct remedy would be to transcribe the image as text into the body of the question, optionally adding more information but not subtracting relevant information.  The screenshot showed that you were getting normal ls output after the error message.  You should edit your question to restore that information. Aug 14 at 19:08

1 Answer 1

8

Bash can process the text of the current command before running it by enabling the DEBUG trap. This was originally intended for debugging, but it is somewhat commonly used to set the window title to the text of the command while it's running.

The extdebug bash option tweaks the way the DEBUG trap works. One of its effects is that if the code of the DEBUG trap returns a nonzero status, the command is not executed.

Your configuration in VSCode has a DEBUG trap set (trap -p DEBUG shows the code if set). This is very likely done to set the window title to the text of the running command. It appears that this code has a bug, and tries to pass the command in a printf format. This breaks when the command contains a backslash or a percent sign. Because the extdebug option is apparently enabled (I don't know why), the following command is not executed.

The solution is to either fix the buggy code, unset the trap (trap - DEBUG) or override the trap with other, non-buggy code (trap 'other, non-buggy code' DEBUG).

This is a bug in the __vsc_preexec_only function or another function that it calls. Thus, presumably, it's a bug in VSCode. As noted by Stéphane Chazelas, that bug has already been reported (and at the time of writing, there's a fix, but the fix is still buggy, it looks like the maintainers of that code don't understand what they're doing).

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.