1

terminal cd . result in following weird error in the terminal buffer:

executing job failed: No such file or directory

The same error appears for term_start('cd .'). It doesn't matter which directory i cd to, the error doesn't change.

If i execute terminal without command, than execute cd . in the opened terminal, everything works fine.

I'm using vim8.1 include patches 1-1282 on Ubuntu 16.04.6 .

update

Based on help from comment and answer, i change command to

terminal bash -c 'cd .'

but it results in following error:

.': -c: line 0: unexpected EOF while looking for matching `''
.': -c: line 1: syntax error: unexpected end of file

buffer name of the terminal is:

!bash -c 'cd .'

If i replace single quote to double quote, the command works. But why?

  • Im not sure i understand why you would do this—the terminal would just execute a cd and then exit, so the net effect for you is absolutely nothing. – D. Ben Knoble May 6 at 13:15
  • I need to cd to bin and do something, i thought that doesn't change the problem, so i make the case as simple as possible. – dedowsdi May 6 at 13:20
  • Gotcha. That makes sense. – D. Ben Knoble May 6 at 13:21
  • 2
    I believe cd is actually an internal shell command and not actually a binary. See also this answer: unix.stackexchange.com/a/50025/303213 and here: unix.stackexchange.com/a/116972/303213 – Christian Brabandt May 6 at 17:08
  • @ChristianBrabandt Thanks, very helpful. – dedowsdi May 6 at 23:50
2

Based on Chris’s comments on the OP, I would make the shell do the work, using a level of indirection:

terminal bash -c "cd wherever && do_something"

The issue is that the bare :terminal command doesn’t ever execute a shell—it executes the name of the external program you give it (which, by default, happens to be the shell). So, terminal cd . tries to run a command on disk named cd. For reasons, you don’t have one, and it wouldn’t work if you did.

  • Not working well, see update. – dedowsdi May 7 at 2:23
  • @dedowsdi dang. Must be vim’s command line doing something weird with the quotes. Ill check it out in the morning – D. Ben Knoble May 7 at 2:25
  • 1
    use double quotes. not sure what single quotes do here. – Christian Brabandt May 7 at 5:42
  • @ChristianBrabandt theyre just easier to type. I wouldn’t have thought it made a difference in this particular case – D. Ben Knoble May 7 at 13:35
  • 2
    :terminal run command as job, job_start split command by white space and pass result list to execvp(), only arguments in double quotes can contain white space. Don't know the reason behind the choice of double quotes, but i can settle for that. – dedowsdi May 12 at 2:29

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.