Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

Say my pwd is at ~/myproject/ and I have a file in ~/myproject/scripts/com/example/module/

In vim with ctrlp plugin, I can press Ctrl+P, type run_main_ Enter, I am editing that script.

I want to run that script (with some arguments) in bash. And I don't want to type the full path. Is there any way to do that in bash?

share|improve this question
up vote 1 down vote accepted

That's what normally the PATH variable is for. Though, I would not add your whole home-directory to your PATH. Consider adding a dedicated directory (like ~/bin) to add to your path your executables.

However, you could add a function to your ~/.bashrc which allows you to search for and run a script...something like this:

# brun stands for "blindly run"
function brun {
    # Find the desired script and store
    # store the results in an array.
        $(find ~/ -type f -name "$1")

    if [ ${#results[@]} -eq 0 ]; then   # Nothing was found
        echo "Could not find: $1"
        return 1

    elif [ ${#results[@]} -eq 1 ]; then   # Exactly one file was found

        echo "Found: $target"

        if [ -x  "$target" ]; then   # Check if it is executable
            # Hand over control to the target script.
            # In this case we use exec because we wanted
            # the found script anyway.
            exec "$target" ${@:2}
            echo "Target is not executable!"
            return 1

    elif [ ${#results[@]} -gt 1 ]; then   # There are many!
        echo "Found multiple candidates:"
        for item in "${results[@]}"; do
            echo $item
        return 1
share|improve this answer
This is a great script! I changed a bit to meet my need: ` results=($(find ~/ -name "$1")) => results=($(find ./ -type f -name "$1*")) exec $target ${@:2} => $target ${@:2} ` – fqsxr Nov 6 '12 at 2:41
@fqsxr: -type f is good idea, yeah. – Bobby Nov 6 '12 at 8:10

Not exactly what you are looking for, but is pretty good, and built right into the bash you already are using is Ctrl-r

It would be nice if it was more fuzzy, like ctrlp in vim. There are some higher level implementations mentioned here Is there a shell which supports fuzzy completion as in Sublime Text?

You can trick out your entire bash prompt to be more vim-like use readline and .inputrc

share|improve this answer

I also wanted this.
I wrote this little perl script for that, feel free to check it out.
Ctrl-P like command line (bash) script.

share|improve this answer

Execute the current file with sh or alternatively bash:

!sh % some arguments

Perhaps I misunderstood your question. If your intention is not to execute the file from vim but from a regular prompt you can:

  1. add the parent folder of you script to PATH (export PATH=$PATH:/my/scripts/folder/)
  2. make an alias (alias moo=/usr/local/something/moo/
  3. create a function (function moo { sh /usr/local/something/moo/ $@; } )

These are common solutions to your question, I do not know of any employing "fuzzy completion".

share|improve this answer

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.