2

Let's say I have file without execution permission. Now a quick way to open such a file over the CLI is to use xdg-open which uses the system default to open a specific file.

Is it now possible to open files without running permission directly without stating xdg-open?

For example:

./test.pdf

should then open the viewer in case that file doesn't have excecution permission.

magu_
  • 153

2 Answers2

1

Simply put; no.

Files do not 'run', especially not PDF files. The closest you can get is to replace xdg-open with the specific name of the program you want to have started:

evince ./file.pdf

The xdg-open command simplifies this, though, by making use of configured mime types.

Going a bit further, bash scripts work like this because they contain a shebang declaration, which tells the system which program to use to open it (for bash scripts it'd be the bash interpreter). PDFs do not contain this information.

Adam
  • 196
1

I think you can achieve this in some shells. Compare Does bash have a hook that is run before executing a command?

This link may not be the best because in bash it's not as easy as you wish. However it mentions preexec from zsh. My point is: in some shells you can analyze the command line in your own way and take your own actions.