I uses vim 9.1 shipped with bash 5.2.26(1)-release (x86_64-pc-msys) both installed by git-bash.

:h terminal-use says :term will start one "terminal emulator" and ran the job.

Then when I ran /d/msys64/usr/bin/bash -l in "git-bash", all works fine. But when I run :call term_start("/d/msys64/usr/bin/bash -l") it shows one weird sequence of /usr/bin/bash: line x: $'P\315': command not found where "x" keeps increasing from 1 up.

Then I ran :call term_start("/d/msys64/usr/bin/bash -l -v -x") it shows

# Set INFOPATH so it includes users' private info if it exists
# if [ -d "${HOME}/info" ]; then
# fi
+ $'\320\177\001'
/usr/bin/bash: line 1: $'\320\177\001': command not found

The above ending #fi is in "~/.bash_profile" for msys2 which is sourced due to -l. But hexdump ~/.bash_profile -C shows "fi.|" (66 69 0a in hex where | means the file ending and 0a means newline) in the ending without "?". It is weird for such one "?" causing the above $'P\315': command not found loop.

The above msys2 uses the same version of bash and vim as git-bash. Maybe the above workflow of using one bash to open one external bash is weird. Although this problem can probably solved by moving all git-bash configs to msys2 since both use the same version of bash and vim. However, since we already met with this weird situation, I want to know the reason for the ending "?".


After comparing :call term_start("/d/msys64/usr/bin/bash -v -x -l") in vim of git-bash and vim of msys2-mingw-w32. It is due to the locale problem and C.UTF-8 used by git-bash seems not to totally compatible with en_US.UTF-8 which is used in some comments of the scripts used by msys2-mingw-w32. But after changing locale, term_start still can't recongize those characters like the above \320\177\001 although vim can recognize now. Finally, I removed those commments with sed.

However it says about another weird charater error

+ $'\320b\001'
/usr/bin/bash: line 1: $'\320b\001': command not found

Then after the comparasion I added 2 options -i -m (This can solve the above weird character problem maybe due to using interactive_comments when -i) and seemed to found the problem source. git-bash auto installed vim will have the following error when term_start but not when in the bash for the same command.

bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
if [[ $- == *v* ]]; then
+++ [[ hivxBH == *v* ]]

Q (Edited):

When running the same bash invocation command in bash and term_start of vim, why does term_start in vim fail to use -m option for bash which is needed for job control?

  • 1
    @D.BenKnoble Do you say what does . in fi.| mean? Sorry for not saying that. I will edit the question. And when I had some time, I reread the log with options -v -x and seemed to find the problem source. I will update with the new info.
    – An5Drama
    Mar 27 at 14:59
  • It seems like you figured some of it out. I suspect the options matter for whether this is an interactive or login shell. See man bash: this affects what startup files are read.
    – D. Ben Knoble
    Mar 27 at 20:56
  • Thanks for the comment. I have read man bash before writing this post. IMHO -l will make bash read /etc/profile and ~/.bash_profile on my machine. And -i is to make "standard input and error are both connected to terminals" which is important for the above situation. And since for one normal shell invocation in vim term_start, the above himBH seems to be done before invoking bash (checked by putting echo $- in the top of /etc/profile temporarily) and it seems no option to turn off i option (checked by running bash with no options).
    – An5Drama
    Mar 27 at 23:53
  • And shopt -u login_shell doesn't influence the daily usage as the doc says it just sources some files to init. And normally subshell is run with the interactive, non-login mode. In sum, lacking m in the minimal option himBH is the problem. And it can't be turned off by +m when in the interactive mode. It seems not one question related with vi now.
    – An5Drama
    Mar 28 at 14:53
  • 1
    Now the question contiues here superuser.com/q/1837439/1658455.
    – An5Drama
    Apr 1 at 10:07


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.