Super User is a question and answer site for computer enthusiasts and power users. 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

I have been looking for a way to run dos batch files from the cygwin command line without having the enter the extension.

Would that be possible?

Currently, I have to enter the extension otherwise cygwin does not find the batch file.

share|improve this question

migrated from Dec 20 '12 at 5:25

This question came from our site for professional and enthusiast programmers.

Why do you want that? Anyway if your batch file is file.bat, try: 'cmd /C file' – golimar Jan 11 '13 at 10:18
As a work around you can add alias command='command.bat' in your shell .profile – kode Feb 8 '14 at 22:25
up vote 1 down vote accepted

I found no other solution so I did what golimar said.
Here is a simple script that looks for .bat files in a specific directory and creates aliases.
For example if there is a file git.bat in /some/path there will be a alias git that points to it.
Add this to your ~/.bashrc or ~/.zshrc or whatever you're using:

for f in /some/path/*.bat; do alias `basename "${f%.bat}"`=$f; done
share|improve this answer

another workaround is to use the bash internal function command_not_found_handle() like this:

command_not_found_handle() {
    echo "bash: $1: command_not_found_handle()"  >&2
    LOWERCASE_CMD=$(echo "$1" | tr '[A-Z]' '[a-z]')
    [ -f /cygdrive/c/CLIPrograms/${LOWERCASE_CMD}.bat ] && /cygdrive/c/CLIPrograms/${LOWERCASE_CMD}.bat "$@"
    return $?
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .