Thunar fails to launch .desktop file if the Exec=... executable path contains spaces

If we try to launch a .desktop entry file (from Thunar), we may get an error (see 'Steps to reproduce' below).

See also the attached screenshot, which contains notes.

Version information

On Fedora 43: Thunar-4.20.6-1.fc43.x86_64
On Debian 13: thunar=4.20.2-1+deb13u1

The problem only happens if all of the following conditions are met:

  • The desktop launcher file (a .desktop entry file) uses Terminal=true.

  • We launch the desktop launcher using Thunar.

  • The desktop launcher file uses an Exec= line to launch a script or program that contains spaces somewhere in the path or filename.

Steps to reproduce:

  1. The instructions below assume we are using the directory /home/user/Downloads.

  2. Open a terminal in /home/user/Downloads, and enter:

cat > 'debug.sh' <<EOF
#!/bin/sh
echo hello
sleep 30
EOF

cp -av 'debug.sh' 'script with spaces.sh'

cat > 'problem.desktop' << EOF
[Desktop Entry]
Name=PROBLEM
# Error  --> Exec=/home/user/Downloads/script with spaces.sh
# Error  --> Exec='/home/user/Downloads/script with spaces.sh'
# Error  --> Exec="/home/user/Downloads/script with spaces.sh"
# Works! --> Exec=env '/home/user/Downloads/script with spaces.sh'
# Works! --> Exec=/usr/bin/env '/home/user/Downloads/script with spaces.sh'
Exec='/home/user/Downloads/script with spaces.sh'
Terminal=true
Type=Application
StartupNotify=true
EOF
  1. Mark the scripts as executable:
chmod +x 'debug.sh'
chmod +x 'script with spaces.sh'
  1. Ensure that the Exec= path in the problem.desktop desktop launcher file exists. Adjust the problem.desktop file if necessary. You may need to replace /home/user with your home directory.

  2. Try launching the problem.desktop file from the Thunar file manager. Confirm the trust warning and choose Mark As Secure and Launch.

  3. Observe that an error is shown, similar to this:

Failed to execute child process “/home/user/Downloads/script”: Failed to execve: No such file or directory

Additional information:

Workaround:

By prepending env or /usr/bin/env to the Exec= command, we can launch a script (or program) that contains spaces in its path or filename.

Remarks:

If we use xdg-open problem.desktop, we do not need the workaround. It's only when launching the desktop launcher file from Thunar that the problem presents itself (if the earlier described conditions are met).

Conclusion:

Currently, there seems to be no way to launch (from Thunar) a script that contains spaces in the path without using a workaround such as the env or /usr/bin/env workaround. Hence the bug report.

Probably, when Thunar encounters a desktop launcher file with Terminal=true, different parsing code is used, and it appears to be related specifically to finding the $0 argument that's passed to execve(). If we pass arguments to the script that contain spaces, and those arguments contain spaces as well, those arguments are passed correctly to the script. For example, if we pass an argument "hello world", then $1 is set to hello world, instead of setting $1 to hello and $2 to world. So the arguments are passed correctly, spaces are preserved. It's just that the $0 argument (the path to the script itself) is incorrectly parsed, and this only happens when the desktop launcher file uses Terminal=true. The bug doesn't occur when we use Terminal=false, and in that case we can observe the script to be running if we use ps auxfww | grep -iF 'script with spaces.sh'.

Screenshot:

screenshot

Edited by Jelle Geerts