Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

How does Linux recognize and process .desktop files?

+3
−0

A Desktop entry (.desktop file) is an executable plain text file, which lacks a shebang. Its contents typically look like:

[Desktop Entry]
Name=Fancy Example
Exec=/usr/bin/example --enable-fancy

(with more possible lines after that). This is clearly not valid as a shell script:

$ [Desktop Entry]
[Desktop: command not found

However, actual shell scripts don't need to have a shebang:

$ cat > test.sh
echo foo
$ chmod +x test.sh 
$ ./test.sh 
foo

How does my system know that the desktop entry is indeed a desktop entry, and feed it to the appropriate interpreter, rather than trying to interpret it as a shell script?

... and what exactly is "the appropriate interpreter"?

History

0 comment threads

1 answer

+2
−0

Upon further investigation, .desktop files don't actually work by executing them. Attemping to run them in a terminal will fail as expected:

./fancy.desktop: line 1: [Desktop: command not found
./fancy.desktop: line 2: Example: command not found
./fancy.desktop: line 3: --enable-fancy: command not found

It appears that Nemo (ab)uses the executable permissions bit on these files as a "trusted" marker (since they after all represent an arbitrary command to run). When you create a "launcher" using the GUI, it sets chmod +x on the resulting file; if you chmod -x and then try to double-click the launcher, Nemo will pop up a warning that the launcher is "untrusted" and offer the option to run it anyway or to mark it as "trusted" (which just sets the permission again).

But the file isn't going through any kind of command processor or being recognized by a file magic number (like the #! bytes of a shebang line); the logic is implemented by Nemo, not by any internal Linux mechanism (such as binfmt_misc). I suppose it would be possible to implement a command-line .desktop file processor and register it with binfmt_misc, but it's hard to imagine a use case.

History

0 comment threads

Sign up to answer this question »