0

In cmd.exe, I try to append WSL2 output to some file, like this:

C:\somepath>echo Some contents> somefile

C:\somepath>bash.exe --noprofile --norc -c "echo APPEND">> somefile
Processing fstab with mount -a failed.


C:\somepath>type somefile
APPEND
ntents

C:\somepath>

As you can see, somehow the output is not appended to the file but overwrites the start of the file. I cannot imagine this is by design somehow.

It only happens with WSL or Bash, not with regular commands of course. But I would expect cmd to be responsible for writing to the correct place. What is so special about WSL output?

The "Processing fstab with mount -a failed." is a line I see with every WSL invocation. I don't think it's related...?

1 Answer 1

0

The boundaries between Windows and WSL/Linux are not well-defined, so sometimes there would be strange side-effects.

In your case, probably bash didn't know that somefile had some data already in it, so it just overwrote the beginning of the file's contents.

You could formulate the command differently, so as to avoid crossing too many boundaries :

bash.exe --noprofile --norc -c "echo APPEND >> somefile"
3
  • Your problem with "Processing fstab with mount -a failed" might be because you have installed several distributions with the wrong one set as default. See also this post.
    – harrymc
    Commented Dec 6, 2022 at 14:50
  • Moving the >> into bash would require translating file paths :-( And all I have is Ubuntu (Default). Commented Dec 6, 2022 at 14:51
  • It worked for me without file translation.
    – harrymc
    Commented Dec 6, 2022 at 14:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .