"Command not found" error when running bash from anywhere but Cygwin desktop shortcut

18,131

Solution 1

  1. In the directory C:\cygwin64\ there should file Cygwin.bat(it will run bash in Windows's terminal aka CMD), use it instead of mintty or if you prefer mintty console then you need to start it as \full\path\to\mintty - (the dash - character is part of the command !!! ) to setup correctly cygwin's environment. Correct this in your " AutoHotKey script" to resolve your issue.
    The dash - character on the end of mintty do the same as bash -l - it used as login shell. If you using mintty without dash on the end it behave as ordinary exe file without setup cygwin environment, but with - option it emulate normal "login" to the system.
  2. Make sure programs you looking for
    killall man info wc which ssh clear
    installed by running cygwin installation file setup.exe again and type these program in search field, you will see in the list if they checked as installed or not. Check to install them and proceed next if it isn't marked as installed.
  3. When you calling ping you running windows version of ping, not cygwin's, if you installed ping package when you installed cygwin you need to call it with full path where it located
    C:\cygwin64\bin\ping.exe (or /bin/ping if you inside of cygwin's terminal), otherwise window's version of ping will be executed.

Cygwin can be used in two modes of operation: one, it when you call cygwin's utility directly from any windows programs or bat files (use grep for example in your bat files), second mode of operation when you want to emulate unix based operation system, to do that you need to login to the virtual operation system aka cygwin, this way mintty - terminal ( or bash -l) will setup properly all environment as it is when you login to real unix based operation system.

Solution 2

To have the PATH properly set you need to tell mintty to run the shell as login shell.

possible ways:

C:\cygwin64\bin\mintty.exe -
C:\cygwin64\bin\mintty.exe /bin/bash -l

See man mintty for details.
Without the - or the proper bash command the PATH is still the windows one without the Cygwin directories.

Share:
18,131

Related videos on Youtube

Hashim Aziz
Author by

Hashim Aziz

Updated on September 18, 2022

Comments

  • Hashim Aziz
    Hashim Aziz over 1 year

    I'm running Cygwin 64-bit on Windows.

    When I launch an instance of mintty using the "Cygwin64 Terminal" desktop shortcut that comes with the Cygwin installation, it runs fine and all installed commands work.

    However, when I launch mintty.exe, from where it's contained at C:\cygwin64\bin, I get a command not found error.

    I also have an AutoHotKey script set up that launches a mintyy.exe instance at the Desktop directory on the press of a NumPad key. When mintyy is launched this way, it also gives a command not found error. cding to any other directory, or doing cd on its own, doesn't fix this either. All that seems to matter is where the mintty instance was initially run from.

    A few of the commands that display errors are:

    killall
    man
    info
    wc
    which
    ssh
    clear
    

    Most of these are included as part of the base Cywgin package, and are therefore definitely installed as part of the Cygwin instllation, so I'm really not sure what's going on here.

    Commands that do work generally seem to be limited to those listed when I do help in the terminal. Here's the whole ouput of that command.

    $ help
    GNU bash, version 4.4.12(3)-release (x86_64-unknown-cygwin)
    These shell commands are defined internally.  Type `help' to see this list.
    Type `help name' to find out more about the function `name'.
    Use `info bash' to find out more about the shell in general.
    Use `man -k' or `info' to find out more about commands not in this list.
    
    job_spec [&]                            history [-c] [-d offset] [n] or hist>
    (( expression ))                        if COMMANDS; then COMMANDS; [ elif C>
    . filename [arguments]                  jobs [-lnprs] [jobspec ...] or jobs >
    :                                       kill [-s sigspec | -n signum | -sigs>
    [ arg... ]                              let arg [arg ...]
    [[ expression ]]                        local [option] name[=value] ...
    alias [-p] [name[=value] ... ]          logout [n]
    bg [job_spec ...]                       mapfile [-d delim] [-n count] [-O or>
    bind [-lpsvPSVX] [-m keymap] [-f file>  popd [-n] [+N | -N]
    break [n]                               printf [-v var] format [arguments]
    builtin [shell-builtin [arg ...]]       pushd [-n] [+N | -N | dir]
    caller [expr]                           pwd [-LP]
    case WORD in [PATTERN [| PATTERN]...)>  read [-ers] [-a array] [-d delim] [->
    cd [-L|[-P [-e]] [-@]] [dir]            readarray [-n count] [-O origin] [-s>
    command [-pVv] command [arg ...]        readonly [-aAf] [name[=value] ...] o>
    compgen [-abcdefgjksuv] [-o option] [>  return [n]
    complete [-abcdefgjksuv] [-pr] [-DE] >  select NAME [in WORDS ... ;] do COMM>
    compopt [-o|+o option] [-DE] [name ..>  set [-abefhkmnptuvxBCHP] [-o option->
    continue [n]                            shift [n]
    coproc [NAME] command [redirections]    shopt [-pqsu] [-o] [optname ...]
    declare [-aAfFgilnrtux] [-p] [name[=v>  source filename [arguments]
    dirs [-clpv] [+N] [-N]                  suspend [-f]
    disown [-h] [-ar] [jobspec ... | pid >  test [expr]
    echo [-neE] [arg ...]                   time [-p] pipeline
    enable [-a] [-dnps] [-f filename] [na>  times
    eval [arg ...]                          trap [-lp] [[arg] signal_spec ...]
    exec [-cl] [-a name] [command [argume>  true
    exit [n]                                type [-afptP] name [name ...]
    export [-fn] [name[=value] ...] or ex>  typeset [-aAfFgilnrtux] [-p] name[=v>
    false                                   ulimit [-SHabcdefiklmnpqrstuvxPT] [l>
    fc [-e ename] [-lnr] [first] [last] o>  umask [-p] [-S] [mode]
    fg [job_spec]                           unalias [-a] name [name ...]
    for NAME [in WORDS ... ] ; do COMMAND>  unset [-f] [-v] [-n] [name ...]
    for (( exp1; exp2; exp3 )); do COMMAN>  until COMMANDS; do COMMANDS; done
    function name { COMMANDS ; } or name >  variables - Names and meanings of so>
    getopts optstring name [arg]            wait [-n] [id ...]
    hash [-lr] [-p pathname] [-dt] [name >  while COMMANDS; do COMMANDS; done
    help [-dms] [pattern ...]               { COMMANDS ; }
    

    However, even more confusingly, ping is not part of this list, but also works.

    Anyone have any idea what's going on here?

  • Hashim Aziz
    Hashim Aziz about 7 years
    Good point about the CMD ping. As for point 1, I'd rather use the mintty terminal, I prefer how it looks and behaves to CMD. As for point 2: as mentioned, most of the commands that are failing are already installed as part of the base Cygwin installation. Regardless, I have double-checked, and everything that I'm trying to use is installed. This is proven by the fact that - as the question also states - they work fine on an instance of mintty that is started via the desktop shortcut.
  • Alex
    Alex about 7 years
    The Cygwin.bat will run the same mintty but in correct way, it will switcth to cygwin's directory and will login to the session. As about killall man info wc which ssh clear they all need to be run from directory bin or you need to provide full path to them when lunching. Just checked some of them and it works as it should if I gave them full path
  • Hashim Aziz
    Hashim Aziz about 7 years
    That's incorrect. Cygwin.bat runs bash using CMD as its terminal. There must be a way to do what you're saying with the terminals that Cygwin comes with, otherwise it would be entirely pointless to include them as packages.
  • Hashim Aziz
    Hashim Aziz about 7 years
    If that's the case for the faulty commands, why do they work when running mintty from the "Cygwin Terminal" desktop shortcut?
  • Alex
    Alex about 7 years
    Check my updated answer, if you don't like windows's cmd console and prefer mintty then you need to run it as it shown in my answer
  • Hashim Aziz
    Hashim Aziz about 7 years
    Honestly, you're not really answering any questions at all. So far, you've done nothing but provide pointless workarounds, and even in doing that you've shown that you don't really understand how Cygwin functions. I'm starting to doubt whether you've had experience with it at all. I'm looking for an answer to a very specific problem here, one which I documented the full details to in a long question. If you don't have the knowledge required to answer that question, then it'd be much more helpful for everyone if you refrained from posting an answer.
  • Alex
    Alex about 7 years
    Did you tried to run mintty - before you made such conclusion ? May be my english write up not good enough, but I answer technically correct all of your questions and if you would do that what I advised you will resolve your issue
  • Hashim Aziz
    Hashim Aziz about 7 years
    Okay, the latest version after the edits has solved the problem. I wish we could have gotten there without the edits and numerous other workaround solutions, but thanks anyway.
  • Alex
    Alex about 7 years
    Well, I'm sorry, but I needed to get understand your issue first. It's often not clear at first glance where problem is especially with multiple issues(ping, absents of listed commands that turns that cygwin simply cant find it in path), but after some questions and answers in comments when both sides stay on the same page problem usually could be solved positively. Anyway, I'm glad I was able to help you
  • Hashim Aziz
    Hashim Aziz about 7 years
    Fair enough. I'm sorry if I was short with you, like I said on the other question, I've not slept today.
  • Alex
    Alex about 7 years
    I wish every problems between people would be resolved such way as we did.