1

I recently began messing with Desktop Entries in order to run some scripts at Gnome startup.

I've read through some freedesktop documentation, as well as this post on creating a startup script. I currently have a desktop entry working on startup, but it is not behaving in the way I was made to understand it should.

Some system info: this is CentOS7 running on VirtualBox in Windows

This is my desktop entry:

[Desktop Entry]
Name=fixres
GenericName=Resolution Fixer
Comment=Changes resolution to 1920x1080
Exec=bash /home/detroitwilly/scripts/fixres.sh
Terminal=false
Type=Application
X-GNOME-Autostart-enabled=true

The script being executed uses xrandr to add a new resolution mode and apply it to my virtual display.

Now, the first line in the script has the shebang #!/bin/bash. My understanding is that if the shebang is on the first line of the script, I shouldn't need to specify bash in the Exec= line of the desktop entry. Note that if I remove bash from the Exec= line, the application will not run.

I've also verified that /bin is in my $PATH variable, so I should automatically have access to bash.

Any ideas as to why i need to prepend the path to my script with bash?

Thanks!

Christopher
  • 15,911
detroitwilly
  • 113
  • 3

1 Answers1

2

There are two portions required to execute a BASH script directly:

  1. the shebang
  2. the executable bit

The shebang should look as follows.

#!/usr/bin/env bash

(Using env is a best practice. It can also be written as the full path, e.g. #!/bin/bash.)

Then set the executable bit as follows.

chmod +x /home/detroitwilly/scripts/fixres.sh
Christopher
  • 15,911