This test.sh
script:
cd test-1
source .venv/bin/activate
python test.py
deactivate
runs fine from the terminal on Ubuntu 20.04.6 with this command:
nick@jetson:~$ ./test.sh
When I add it to Startup Applications Preferences with:
it doesn't run. What is wrong?
This question is different from How do I start applications automatically on login?. I'm not asking how do I start applications automatically on login. I'm asking why a different command has to be used in Command
line of Add Startup program
than the command I type in the terminal in ~
folder.
When you create a "Startup application", what happens under the hood is:
~/.config/autostart
, containing anExec
line that contains the "command" you specified;Quoting the relevant section from the page (emphasys mine):
So the reason why
./test.sh
fails simply is: it doesn't comply with any of the Freedesktop's specifications, as it's neither a full path nor a name of an executable.Also note that there are more rules that a "command" needs to abide to (you can find them in the page I linked), but going through these checks usually works:
PATH
, you need to put in the full path, otherwise you can put in just the bare name of the executable;env
(env foo=bar executable
). If you need something more, you can mostly usesh -c
/bash -c
(sh -c '<input command1 | command2'
), or create a wrapper script around your actual script.If your script really doesn't have a shebang (
#!/bin/bash
), one solution would be to run:instead. However the "correct" solution would be to add a shebang to the script and run just:
The shebang is required in other contexts (such as when running the script from a shell that is not Bash) to make use of Bash features, such as e.g.
source
when the script is run fromsh
.