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
  • 1
  • 8
  • I know that with `oh-my-zsh` you can use `~/directory` similarly to `cd ~/directory`, so... perhaps. – theoden8 Aug 07 '15 at 19:26
  • Hm, yes maybe this would depend on the terminal used. In this case it would be great to get an answer working for either gnome-terminal or tcsh. Of course bonus points for a terminal independent solution. (Some fancy alias solution maybe I don't know about maybe) – magu_ Aug 07 '15 at 19:35

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
  • 2
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.

Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
  • I think that's what I was looking for. I'll try to make if work this week. I think this link (https://stackoverflow.com/questions/28099966/use-preexec-to-evaluate-entered-command) also has relevant information to achieve this. – magu_ Oct 01 '17 at 18:28