Ensure POSIX-compliant shell scripting to support DASH
Some systems, such as Ubuntu, use DASH to provide /bin/sh
instead of BASH.
This means that we need to use POSIX compliant shell scripting as BASHisms are
unsupported in DASH. There are two BASH variable substition instances within
the code of xdg-settings.in
that cause KDE users to be unable to find the
current web browser because the script dies when hitting this unsupported code.
DASH also doesn't support the BASHism that allows ==
inside []
tests.
- Replace
${variable:0:1}
withprintf
-based equivalent. - Replace use of
==
with=
Fixes #10 (closed), #203 (closed)
Signed-off-by: Lucy Llewellyn lucyllewy@ubuntu.com
Merge request reports
Activity
When testing this on Ubuntu 22.04 in the context of https://bugs.launchpad.net/ubuntu/+source/xdg-utils/+bug/1970594, I'm observing this:
$ xdg-settings check default-web-browser firefox.desktop /usr/bin/xdg-settings: 734: [: x!: unexpected operator yes
So the output is as expected, but there is an "unexpected operator" error on stderr.
- Resolved by Lucy Llewellyn
It looks like DASH doesn't like
"!"
while BASH is ok with it. I think the solution is to escape it with"\!"
added 1 commit
- 72275fa6 - Add string escaping to appease DASH on Ubuntu
mentioned in issue #203 (closed)
added 1 commit
- 8996594d - Fix use of `==` to `=` for Ubuntu, because DASH doesn't support `==` inside `[]` tests
Thanks! For information, I have uploaded the updated patch to Ubuntu 22.10 (and will SRU it to 22.04 in due course): https://launchpad.net/ubuntu/+source/xdg-utils/1.1.3-4.1ubuntu3.
mentioned in merge request !54 (closed)
Good catches. I also fixed another bashism in !24 (17c7c995).
234 234 binary="`resolve_kde_browser`" 235 235 236 236 # The browser may contain a relative entry to the binary starting with ! 237 if [ x"\!" == x"$(printf %.1s "$browser")" ]; then 237 if [ x"!" = x"$(printf %.1s "$browser")" ]; then It's maybe worth noting in the commit message that
==
is a non-portable alias in bash that is exactly identical to=
.Personally, I'm disappointed that it even exists in bash -- it doesn't really do anything other than confuse people, I strongly recommend using
=
even in bash scripts....
Anyway, it is incorrect to mention Ubuntu, or alternatively, the commit message should probably say "systems such as Ubuntu". There are certainly other systems where the
sh
shell is dash or another non-bash shell. :)
- Resolved by Elvis Stansvik
Also Fixes #203 (closed), let me see if I can add that to the overview to auto close that bug
mentioned in issue #165 (closed)
added 1 commit
- a114fc51 - Ensure POSIX-compliant shell scripting to support DASH
added 24 commits
-
a114fc51...5f14673f - 23 commits from branch
xdg:master
- 301a1a47 - Ensure POSIX-compliant shell scripting to support DASH
-
a114fc51...5f14673f - 23 commits from branch