[SOLVED] XFCE - Can't run .sh file via double-clicking it if the file name has a space or apostrophe (works in Cinnamon)

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
NM64
Level 4
Level 4
Posts: 245
Joined: Sat Feb 04, 2017 11:34 pm

[SOLVED] XFCE - Can't run .sh file via double-clicking it if the file name has a space or apostrophe (works in Cinnamon)

Post by NM64 »

On Mint 20.3 XFCE, regardless of whether it's a live USB session or and installed session, I can't seem to run .sh files if they have a space or an apostrophe in the file name.

I'm also running into this issue when the .sh file is located in a folder that has an apostrophe or space, even if the .sh file itself does not; e.g.

Code: Select all

/folder's_name/script.sh
as well as

Code: Select all

/folder name/script.sh
will both fail.

And yes, the "run as a program" checkbox in right-click -> properties is checked.

For reference, this issue does not occur with Mint 20.3 Cinnamon (I have not tried it on Mate). I've also not tried it on any other XFCE version of Mint other than 20.3.

EDIT: To clarify, all I'm trying to do is double-click on the .sh file through Thunar on XFCE. In Nemo on Cinnamon, it all "just works" regardless of whether there's a space or an apostrophe but, in Thunar on XFCE, it does not (it may be worth mentioning that Thunar on XFCE was by default set to open .sh files with the text editor even when "run as a program" was checked, so I had to set .sh files to instead open with the terminal by default so that double-clicking on them would actually run them).


Simply renaming the file name to not have a space or apostrophe makes it work fine, but a least one program I was trying to run has an apostrophe in its .sh file by default (and renaming it causes issues with the .py file that it normally hooks into using the same file name).

All tests were conducted with the .sh file being located in "Home" and/or on the desktop, and additionally were tested inside of a newly-created folder in those locations.

If you want an example .sh script that I tested with, here's one I "borrowed" from this thread; a file name of:

Code: Select all

hello world.sh
as well as

Code: Select all

world's hello.sh
does not work while

Code: Select all

hello_world.sh
does in fact work:

Code: Select all

#!/bin/bash
# hello world script!
echo 'hello world'
read -n 1 -r -s -p $'Press any key to continue...\n'
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 8 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
CPU: Xeon E3-1246 v3 (4c/8t Haswell/Intel 4th gen) — core & cache @ 3.9GHz via multicore enhancement
GPU: Intel integrated HD Graphics P4600
RAM: 4x8GB Corsair Vengence @ DDR3-1600
OS: Linux Mint 20.3 Xfce + [VM] Win7 SP1 x64 
bin
Level 4
Level 4
Posts: 228
Joined: Wed Nov 22, 2006 12:12 pm
Location: Wiltshire UK

Re: 20.3 XFCE - Can't run a .sh file if it has a space or apostrophe in the file name? (but it works in Cinnamon...)

Post by bin »

The way I would expect this to work is that if the path to the sh file contains a space then I would put " " at both ends of the path.

So

Code: Select all

/home/user/scripts/my script.sh 
would fail because it could not find a path after

Code: Select all

/home/user/scripts/my
due to the space

But

Code: Select all

"/home/user/scripts/my script.sh"
would work

If you are in the folder where the script lives then it would be

Code: Select all

./"my script.sh"
I cannot tell from your posts whether the use of " " is to provide this functions or simple to show what you have run.
It would help if you uses the code button in the post toolbar to isolate what you are actually entering.

Apostrophe is just asking for trouble for so many reasons.
User avatar
NM64
Level 4
Level 4
Posts: 245
Joined: Sat Feb 04, 2017 11:34 pm

Re: 20.3 XFCE - Can't run a .sh file if it has a space or apostrophe in the file name? (but it works in Cinnamon...)

Post by NM64 »

Oh yeah using the code bbcode would have been better... I'll fix that.

As for using quotes, that won't work because all I'm trying to do is straight-up double-click on the .sh file in question through Thunar on XFCE. In Nemo on Cinnamon, it all "just works" regardless of whether there's a space or an apostrophe but, in Thunar on XFCE, it does not. I'll edit that into my first post as well.

(it may be worth mentioning that Thunar on XFCE was by default set to open .sh files with the text editor even when "run as a program" was checked, so I had to set .sh files to instead open with the terminal by default so that double-clicking on them would actually run them)


And with regards to the apostrophe, that's part of the program that I simply can't change as .sh files is how one launches a Ren'Py VN (visual novel) natively on Linux. The following is a small example (~50MB) of a freely-available Ren'Py VN that you can use to see what I mean: Now admittedly the file name of that example is simply "camera.sh" so it doesn't have the issue in question, but you can at least use it to see that renaming the .sh file to anything else will cause the VN to no longer launch. This means that, if the VN has an apostrophe in the file names of the .sh and .py files, then it will not work in Thunar on XFCE despite working without any issue in Nemo on Cinnamon.

(to clarify, I cannot link you to the actual Ren'Py VN that uses the apostrophe in its name)
CPU: Xeon E3-1246 v3 (4c/8t Haswell/Intel 4th gen) — core & cache @ 3.9GHz via multicore enhancement
GPU: Intel integrated HD Graphics P4600
RAM: 4x8GB Corsair Vengence @ DDR3-1600
OS: Linux Mint 20.3 Xfce + [VM] Win7 SP1 x64 
bin
Level 4
Level 4
Posts: 228
Joined: Wed Nov 22, 2006 12:12 pm
Location: Wiltshire UK

Re: 20.3 XFCE - Can't run .sh file via double-clicking it if the file name has a space or apostrophe (yet works in Cinna

Post by bin »

The way I normally get round this is to use a .desktop file to launch in XFCE

So, this is from script.desktop

Code: Select all

[Desktop Entry]
Version=1.0
Type=Application
Name=script
Comment=
Exec="/home/robin/Videos/hello_world.sh"
Icon=
Path=
Terminal=true
StartupNotify=false
which works fine. However it does still baulk at spaces and apostrophes. On the other hand

Code: Select all

"hello' world"
will run from the command line.

Not sure if that helps...
User avatar
NM64
Level 4
Level 4
Posts: 245
Joined: Sat Feb 04, 2017 11:34 pm

Re: 20.3 XFCE - Can't run .sh file via double-clicking it if the file name has a space or apostrophe (yet works in Cinna

Post by NM64 »

Next-day UPDATE: From what I can tell, associating .sh scripts to open in the terminal when double-clicked isn't actually the same as what Cinnamon does by default, and the function that Cinnamon uses actually does exist in XFCE but is disabled by default: This is an important distinction because that aforementioned "disabled by default" double-click-to-run function does work with .sh files and/or folders that have spaces and apostrophes in their file name, so simply enabling that function in XFCE solves the issue.



________Original post________
bin wrote: Mon Jan 24, 2022 5:23 am The way I normally get round this is to use a .desktop file to launch in XFCE

which works fine. However it does still baulk at spaces and apostrophes.
If it complains about spaces and apostrophes, then what is the benefit vs just double-clicking the .sh file directly? Double-clicking works fine if there's no spaces or apostrophes if you configure via right-click -> "open with" that .sh files open with the terminal by default rather than the text editor
.
bin wrote: Mon Jan 24, 2022 5:23 am On the other hand

Code: Select all

"hello' world"
will run from the command line.
That makes me wonder if it could work with the ./script.sh trick where you can have a .sh file run another .sh so that I could do something like the following:

run_first_script.sh

Code: Select all

./"second script's filename.sh"
EDIT: Sure enough that works! It doesn't really "solve" the issue though, especially since one still has to rename the folder if it too contains a space or apostrophe... unless maybe one could make an additional sub-folder and have the custom script located outside of it? e.g.

/folder/run_first_script.sh

Code: Select all

./"folder's contents/second script's filename.sh"
so in total the folder tree would be:
  • /folder/run_first_script.sh
  • /folder/folder's contents/second script's filename.sh
EDIT 2: Yup, that works too. And one can even cheat and replace any apostrophes with a ` (the key above tab and left of 1) as well as replace spaces with one of their unicode equivalents such as this one that's just a little bit wider (or alternatively this one that seems to be the same exact size)
CPU: Xeon E3-1246 v3 (4c/8t Haswell/Intel 4th gen) — core & cache @ 3.9GHz via multicore enhancement
GPU: Intel integrated HD Graphics P4600
RAM: 4x8GB Corsair Vengence @ DDR3-1600
OS: Linux Mint 20.3 Xfce + [VM] Win7 SP1 x64 
Locked

Return to “Beginner Questions”