You are not logged in.
I wanted to create a custom .desktop entry for an appimage to later use xdg-open in a script, but I keep running into the same error. I tried troubleshooting this by creating a test.desktop and a new mimeapps.list file:
~/.local/share/applications/test.desktop:
[Desktop Entry]
Type=Application
MimeType=text/plain
Exec=sh -c "echo Hello"~/.config/mimeapps.list:
[Default Applications]
text/plain=test.desktopNow, running `xdg-open x.txt` on a text file (with content) corresponds to my test.desktop entry. Below is my output of xdg-open (changing only the "Exec=" line):
Exec=sh -c "echo Hello"
$ xdg-open x.txt
Hello": -c: line 1: unexpected EOF while looking for matching `"'Exec=echo Hello
$ xdg-open x.txt
Hello x.txtExec=sg wheel "/x.appimage %f"
$ xdg-open x.txt
sh: -c: line 1: unexpected EOF while looking for matching `"'Is this to be expected? From the searching I've done it's not. I even tried this on my laptop (Debian) and on an Archlinux vm and none had any errors, Hello was printed and my appimage opened. I have no clue what could cause this. I tried creating a new user in case it had to do with my config but it was the same. All the commands works fine from the terminal. I'd appreciate it if anyone could test the first Exec=sh -c ... command and see whether it works. Thanks for reading!
Last edited by computernoob (2024-05-11 06:51:41)
Offline
xdg-open will likely pass the Exec command to your $SHELL (otherwise "echo Hello" would not work) and quote the string itself.
Use single quotes or escape the quotes.
tried this on my laptop (Debian) and on an Archlinux vm and none had any errors
I tried creating a new user in case it had to do with my config but it was the same
Do you use the same login shell on all systems (and similar-ish rc's)?
/usr/bin/xdg-open is a shell script, if you put "set -x" below the shebang, it'll trace the execution and tell you what's actually going on there and what is being tried to execute.
Offline
Use single quotes or escape the quotes.
Like this? Neither worked :/
Exec=sh -c 'echo hello'
Exec=sh -c \"echo hello\"In /etc/passwd the user login shell for all machines is "/bin/bash". What rc files are you referring to, those in /etc/? I rarely edit files in root but this system has been running since I registered whereas the other 2 are from last year, something could be different.
I didn't know about set -x! The output was quite long so I only included starting from the first Hello:
++ echo 'Exec=sh -c "echo Hello"'
++ cut -d= -f 2-
++ echo '-c "echo Hello"'
++ read -r line
++ IFS='
'
+ set -- -c '"echo' 'Hello"'
+ local args=3
+ local replaced=0
+ '[' 3 -gt 0 ']'
+ case $1 in
+ arg=-c
+ shift
+ set -- '"echo' 'Hello"' -c
+ args=2
+ '[' 2 -gt 0 ']'
+ case $1 in
+ arg='"echo'
+ shift
+ set -- 'Hello"' -c '"echo'
+ args=1
+ '[' 1 -gt 0 ']'
+ case $1 in
+ arg='Hello"'
+ shift
+ set -- -c '"echo' 'Hello"'
+ args=0
+ '[' 0 -gt 0 ']'
+ '[' 0 -eq 1 ']'
+ set -- -c '"echo' 'Hello"' x.txt
+ env sh -c '"echo' 'Hello"' x.txt
Hello": -c: line 1: unexpected EOF while looking for matching `"'
+ exit_success
+ '[' 0 -gt 0 ']'
+ exit 0sh -c '"echo' 'Hello"' x.txt clearly is wrong, seems like the arguments split on spaces. I don't really know what else to take from this. Also tracing the VM I did notice that it did not try to split any string, instead it set DE=xfce and called exo-open. Is that it? I had no idea xdg-open was DE specific, on this PC I use DWM and it set DE=generic. If this is the case what other options do I have?
Offline
Is that it?
Most likely.
The tokenizer there doesn't handle any grouping so the easiest solution (if an option) would be to wrap the comand into a shell script.
Sth. like
Exec=wheel_x %f/usr/local/bin/wheel_x
#!/bin/sh
exec sg wheel "/x.appimage \"$1\""Offline
According to the specification I think the escaped quotes should have worked or do I read that wrong?
https://specifications.freedesktop.org/ … -variables
Arguments may be quoted in whole. If an argument contains a reserved character the argument must be quoted. The rules for quoting of arguments is also applicable to the executable name or path of the executable program as provided.
Quoting must be done by enclosing the argument between double quotes and escaping the double quote character, backtick character ("`"), dollar sign ("$") and backslash character ("\") by preceding it with an additional backslash character. Implementations must undo quoting before expanding field codes and before passing the argument to the executable program. Reserved characters are space (" "), tab, newline, double quote, single quote ("'"), backslash character ("\"), greater-than sign (">"), less-than sign ("<"), tilde ("~"), vertical bar ("|"), ampersand ("&"), semicolon (";"), dollar sign ("$"), asterisk ("*"), question mark ("?"), hash mark ("#"), parenthesis ("(") and (")") and backtick character ("`").
Note that the general escape rule for values of type string states that the backslash character can be escaped as ("\\") as well and that this escape rule is applied before the quoting rule. As such, to unambiguously represent a literal backslash character in a quoted argument in a desktop entry file requires the use of four successive backslash characters ("\\\\"). Likewise, a literal dollar sign in a quoted argument in a desktop entry file is unambiguously represented with ("\\$").
Last edited by progandy (2024-05-10 07:28:30)
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |
Offline
From the spec
Exec=sg wheel "/x.appimage %f""should" work and it clearly does w/ other desktop entry handlers, just not the "generic" built in which would work if it would just replace the "%f" field and feed the resulting string into a shell.
I can't tell why it takes this elaborate and cumbersome approach - both, sed and parameter substitution, are already utilized and would fix this handily.
Offline
Alright.. seems like a separate script will have to do. I spent too much time trying to get this to work as it "should", even considered re-installing (thinking something was up with my system). Happy not having to do that now that we found the reason behind it
. I'll mark solved but please do reply if another solution comes up (not a fan of having an opener script for an opener).
Offline
https://gitlab.freedesktop.org/xdg/xdg- … issues/174
The other option is to replace xdg-open, possibly with mimeo + xdg-utils-mimeo or handlr-regex / xdg-utils-handlr
Last edited by progandy (2024-05-11 07:03:55)
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |
Offline