w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Why does bash not open a file descriptor while opening a file in Sublime or TextEdit but does when opening it in BBEdit?

The open command isn't part of bash - I think it's an OSX thing (maybe BSD?). The question isn't even really about open - it's about how Sublime and TextEdit handle files vs BBEdit.

I was able to verify your results, and am led to believe that TextEdit (and apparently sublime, I don't have it) doesn't hold the file open while you're editing. I wrote a quick little ruby script ( since it's such a lovely easy language ) to open a file and hold it open for 10 seconds...

File.open "open.txt", "r" do |f|
    sleep 10

and I noticed it showed up in lsof:

$ lsof open.txt
ruby    6531 dfarrell    5r   REG    1,4       14 7602637 open.txt

You may want to consider using opensnoop to watch the file opens as they happen on the file in question. I found best results running sudo opensnoop | grep TextEdit.*open.txt. As we know, it does open the file, it apparently reads it into a buffer and then closes the file descriptor again when it's done reading/writing. FYI, vim seems to do the same thing.

Hope it helps!

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.