1

When I try executing a *.sh file, I can run it from terminal, but not when double-clicking it form the file manager. The commands chmod +x Test.sh and chmod -x Test.sh dont seem to work. Every time I double-click the file, it opens on my Text Editor. Here is the text in my file:

#!/bin/bash

xdg-open https://www.google.com

cd home/<username>/Desktop

mkdir Test
cd Test
touch test.txt

The distro that I use is Ubuntu 20.04.

Games 08
  • 61
  • 2
  • 12

3 Answers3

1

chmod -x Welcome.sh is your exact problem.

-x is the same as u-x, or "remove the execute permission from my user". You need to add the execute permission with chmod +x Welcome.sh.

Also: You can change directory to your user home (if that's what username is) with just cd ~ or cd. If it's another user's $HOME, then use cd /home/<user>.

0xLogN
  • 111
  • 5
0

You can use xdg-mime query filetype shell_script.sh to find the mime type of the script. Afterwards, use xdg-mime query default mime_type to see the current default application associated with the mime type, which is called upon xdg-open invocation. Then you can use xdg-mime default default_application.desktop mime_type to set the default application to be used.

The command output on my laptop is,

$ xdg-mime query filetype /opt/ros/foxy/setup.sh 
application/x-shellscript
$ xdg-mime query default application/x-shellscript
gvim.desktop
SuibianP
  • 72
  • 9
0

I need to log out and back in after marking the file as executable to apply the changes. The fastest way to do this is by using the shortcut Ctrl + Alt + Delete

Games 08
  • 61
  • 2
  • 12
  • This might not help everybody in the same situation, [see this related question](https://unix.stackexchange.com/q/673864/318461) – Cadoiz Oct 20 '21 at 10:50