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:
- A .desktop file is created under
~/.config/autostart, containing an Exec line that contains the "command" you specified;
- On session's startup, the desktop file is parsed and evaluated according to Freedesktop's specifications.
Quoting the relevant section from the page (emphasys mine):
The Exec key must contain a command line. A command line consists of an executable program optionally followed by one or more arguments. The executable program can either be specified with its full path or with the name of the executable only. If no full path is provided the executable is looked up in the $PATH used by the desktop environment. The name or path of the executable program may not contain the equal sign ("="). Arguments are separated by a space.
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:
- If you need to run something not in
PATH, you need to put in the full path, otherwise you can put in just the bare name of the executable;
- You can't use shell-isms (variables, aliases, functions, redirections, pipes and the like). Variables can be injected into the executable's environment using
env (env foo=bar executable). If you need something more, you can mostly use sh -c / bash -c (sh -c '<input command1 | command2'), or create a wrapper script around your actual script.