Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After reading this answer about a zsh feature:

If a given extension has a suffix alias, you can execute a file with that extention directly, and ZSH will launch the given program and pass the filename as an argument.

Is there something similar to bash? That is, if a given file has an extension, how to directly execute that file, automatically launching a program just by calling the file's name? So doing

program /path/to/foo.ext


would equivalent to the same zsh feature? Is this feature available in newer versions of bash?

share|improve this question
up vote 2 down vote accepted

While I am not familiar with every feature of Bash, I do not believe this is a built-in feature of the Bash shell. I was unable to find this feature in the relevant sections of the Bash manual.

You may be able to cobble something together using trap. From help trap:

Trap signals and other events.

Defines and activates handlers to be run when the shell receives signals or other conditions.

Thus by using the command:

$ trap my_function ERR

I can ensure that my_function is called whenever a command fails. my_function could be a function that parses the previous command, looking for known extensions and calling the appropriate command based on that extension.

Depending on your interest, writing such a function may be more or less interesting than moving to the z shell.

share|improve this answer
Well, I think using this approach with xdg-open pointed out by @akira because of @NES answer is the way to go. Until them, just an alias do xdg-open is good to me. – Somebody still uses you MS-DOS Feb 10 '11 at 15:50

If you are on Linux, you could try setting up binfmt misc.

share|improve this answer

You could use fish instead of Bash. It has the functionality you're searching and lots interesting more.

For your example. Just type in

open manual.pdf

and it opens the pdf file with the associated program.

share|improve this answer
so your answer is "no." plus: your 'open' is most likely only working on mac in the way you think it works. on linux it is a symlink to openvt which "starts a program on a new virtual terminal". on linux it would be xdg-open or gnome-open. – akira Feb 7 '11 at 15:13
@akira: Indeed, using xdg-open works in my Ubuntu machine. I think I'll just create an "open" alias to xdg-open. – Somebody still uses you MS-DOS Feb 10 '11 at 15:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.