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.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityI 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.
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
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]')
shift
[ -f /cygdrive/c/CLIPrograms/${LOWERCASE_CMD}.bat ] && /cygdrive/c/CLIPrograms/${LOWERCASE_CMD}.bat "$@"
return $?
local
(unless you have a reason to create a global var. In my opinion, it is good style to use lower case for variables and upper case for (pseudo-)constants, although tastes vary. You can use ${1,,}
to lowercase $1, no need for a temp var, subshell and pipe. In case the .bat
file doesn't exist, you want to print the standard "bash: $1: command not found"
and return 127
.
Nov 16, 2016 at 0:11