当我尝试执行外部命令时,为什么我的 Cygwin Bash 总是从终端读取?

当我尝试执行外部命令时,为什么我的 Cygwin Bash 总是从终端读取?

请注意,这不是路径不完整的“命令未找到问题”。外部命令出现开始确定并 立即寻求终端输入而不是产生终端输出。

我想我已经冲洗了我的 .profile / .bashrc 文件等...但我看不到问题的原因。

我使用 mintty 2.5.1 (i686-pc-cygwin) 启动 cygwin bash 交互。运行一些脚本,然后我看到 $ 提示符。 shopt -x 已设置,因此我看到命令回显。

(MinGW 也已安装,并且位于 cygwin 之后的 DOS 路径中。)

我输入的任何外部命令都会通过从终端读取行来响应。我可以恢复 $ 提示符的唯一方法是执行一些 ctrl-c 并输入。

这是终端输出,从 cygwin 启动的脚本开始。也许前面的某个地方是我的错误。最后,我尝试运行命令“mount”和“man mount”,它们用前导“+”(来自 shopt -x)回显命令,然后读取输入。

    + '[' -z '' ']'
    + : /usr/bin:/c:/c/tools:/c/WINDOWS/System32:/c/WINDOWS:/c/WINDOWS/System32/WBEM:/c/WINDOWS/system32/WindowsPowerShell/v1.0:/c/cgywin/bin:/c/MinGW/bin:/c/Documents and Settings/All Users/Application Data/Oracle/Java/javapath:/c/Program Files/rexx.org/Regina:/c/Program Files/rexx.org/THE
    + '[' addwinpath = addwinpath ']'
    + PATH='/usr/local/bin:/usr/bin:/usr/bin:/c:/c/tools:/c/WINDOWS/System32:/c/WINDOWS:/c/WINDOWS/System32/WBEM:/c/WINDOWS/system32/WindowsPowerShell/v1.0:/c/cgywin/bin:/c/MinGW/bin:/c/Documents and Settings/All Users/Application Data/Oracle/Java/javapath:/c/Program Files/rexx.org/Regina:/c/Program Files/rexx.org/THE'
    + INFOPATH=/usr/local/info:/usr/share/info:/usr/info
    ++ /usr/bin/id -un
    + USER=User
    + unset TMP TEMP
    + TMP=/tmp
    + TEMP=/tmp
    + p='/proc/registry/HKEY_CURRENT_USER/Software/Microsoft/Windows NT/CurrentVersion/Windows/Device'
    + '[' -e '/proc/registry/HKEY_CURRENT_USER/Software/Microsoft/Windows NT/CurrentVersion/Windows/Device' ']'
    + read -r PRINTER
    + PRINTER='HP LaserJet Professional P1606dn'
    + unset p
    + umask 022
    + '[' '!' -d '/c/Documents and Settings/User' ']'
    + readonly PROFILEREAD=true
    + PROFILEREAD=true
    + '[' '!' -z '' ']'
    + cd '/c/Documents and Settings/User'
    ++ /usr/bin/hostname
    + HOSTNAME=hej
    + profile_d sh
    + _LC_ALL_SET_=
    + _LC_SAVE_=null
    + LC_ALL=C
    + '[' null = null ']'
    + for file in '/etc/profile.d/*.$1'
    + '[' -e /etc/profile.d/lang.sh ']'
    + . /etc/profile.d/lang.sh
    ++ test -z ''
    +++ /usr/bin/locale -uU
    ++ export LANG=en_US.UTF-8
    ++ LANG=en_US.UTF-8
    + for file in '/etc/profile.d/*.$1'
    + '[' -e /etc/profile.d/tzset.sh ']'
    + . /etc/profile.d/tzset.sh
    ++ test -z ''
    +++ /usr/bin/tzset
    ++ export TZ=America/New_York
    ++ TZ=America/New_York
    + unset LC_ALL
    + unset file
    + unset _LC_ALL_SET_
    + unset _LC_SAVE_
    + '[' '!' 'x4.3.46(6)-release' = x ']'
    + '[' -f /etc/bash.bashrc ']'
    + . /etc/bash.bashrc
    ++ [[ -z '' ]]
    ++ CYG_SYS_BASHRC=1
    ++ [[ himxBH != *i* ]]
    ++ export 'EXECIGNORE=*.dll'
    ++ EXECIGNORE='*.dll'
    ++ PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
    + export PROFILEREAD PATH ORIGINAL_PATH INFOPATH USER TMP TEMP PRINTER HOSTNAME PS1 SHELL
    + echo '.profile in  C:\Documents and Settings\User\.profile'
    .profile in  C:\Documents and Settings\User\.profile
    + set -x
    ++ uname -o
    + [[ Cygwin == \C\y\g\w\i\n ]]
    + export CYGDRIVE=/cygdrive
    + CYGDRIVE=/cygdrive
    + export 'PATH=./://cygdrive/c/bin:/usr/local/bin:/usr/bin:/usr/bin:/c:/c/tools:/c/WINDOWS/System32:/c/WINDOWS:/c/WINDOWS/System32/WBEM:/c/WINDOWS/system32/WindowsPowerShell/v1.0:/c/cgywin/bin:/c/MinGW/bin:/c/Documents and Settings/All Users/Application Data/Oracle/Java/javapath:/c/Program Files/rexx.org/Regina:/c/Program Files/rexx.org/THE:/c/Documents and Settings/User'
    + PATH='./://cygdrive/c/bin:/usr/local/bin:/usr/bin:/usr/bin:/c:/c/tools:/c/WINDOWS/System32:/c/WINDOWS:/c/WINDOWS/System32/WBEM:/c/WINDOWS/system32/WindowsPowerShell/v1.0:/c/cgywin/bin:/c/MinGW/bin:/c/Documents and Settings/All Users/Application Data/Oracle/Java/javapath:/c/Program Files/rexx.org/Regina:/c/Program Files/rexx.org/THE:/c/Documents and Settings/User'
    + export HOME=/cygdrive/g/GNU-GCC/home/User
    + HOME=/cygdrive/g/GNU-GCC/home/User
    + cd /cygdrive/g/GNU-GCC/home/User
    + '[' -f /cygdrive/g/GNU-GCC/home/User/.bashrc ']'
    + . /cygdrive/g/GNU-GCC/home/User/.bashrc
    ++ set -o notify
    ++ set -o noclobber
    ++ set -o ignoreeof
    ++ set -o nounset
    ++ set -o xtrace
    ++ alias 'debug=set -o nounset; set -o xtrace'
    ++ ulimit -S -c 0
    ++ shopt -s checkhash
    ++ shopt -s checkwinsize
    ++ shopt -s sourcepath
    ++ shopt -s no_empty_cmd_completion
    ++ shopt -s cmdhist
    ++ shopt -s histappend histreedit histverify
    ++ shopt -s extglob
    ++ shopt -s nocaseglob
    ++ shopt -s expand_aliases
    ++ shopt -u cdspell
    ++ shopt -u cdable_vars
    ++ shopt -u mailwarn
    ++ unset MAILCHECK
    ++ alias cls=clsb
    ++ set +u
    ++ [[ -z '' ]]
    ++ unalias cls
    ++ alias 'cls=tput reset'
    ++ set -u
    ++ alias 'rm=rm -i'
    ++ alias 'cp=cp -i'
    ++ alias 'mv=mv -i'
    ++ alias h=history
    ++ alias 'j=jobs -l'
    ++ alias 'which=type -a'
    ++ alias '..=cd ..'
    ++ alias 'path=echo -e ${PATH//:/\\n}'
    ++ alias 'libpath=echo -e ${LD_LIBRARY_PATH//:/\\n}'
    ++ alias 'du=du -kh'
    ++ alias 'df=df -kTh'
    ++ alias 'pushnullglob=local nullglob=$(shopt -p nullglob) ; shopt -s nullglob'
    ++ alias 'popnullglob=$nullglob ; unset nullglob'
    ++ alias 'ls=ls -h --color'
    ++ alias 'lx=ls -lXB'
    ++ alias 'lk=ls -lSr'
    ++ alias 'lt=ls -ltr'
    ++ alias 'lc=ls -ltcr'
    ++ alias 'lu=ls -ltur'
    ++ alias 'll=ls -lv --group-directories-first'
    ++ alias 'lm=ll |more'
    ++ alias 'lr=ll -R'
    ++ alias 'la=ll -A'
    ++ alias 'tree=tree -Csuh'
    ++ alias more=less
    ++ export PAGER=less
    ++ PAGER=less
    ++ export LESSCHARSET=latin1
    ++ LESSCHARSET=latin1
    ++ export 'LESSOPEN=|/usr/bin/lesspipe.sh %s 2>&-'
    ++ LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-'
    ++ export 'LESS=-i -w -s -z-4 -g -M -X -r -f -P%t?f%f \
    :stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...'
    ++ LESS='-i -w -s -z-4 -g -M -X -r -f -P%t?f%f \
    :stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...'
    ++ export 'LESS_TERMCAP_mb='
    ++ LESS_TERMCAP_mb=''
    ++ export 'LESS_TERMCAP_md='
    ++ LESS_TERMCAP_md=''
    ++ export 'LESS_TERMCAP_me='
    ++ LESS_TERMCAP_me=''
    ++ export 'LESS_TERMCAP_se='
    ++ LESS_TERMCAP_se=''
    ++ export 'LESS_TERMCAP_so='
    ++ LESS_TERMCAP_so=''
    ++ export 'LESS_TERMCAP_ue='
    ++ LESS_TERMCAP_ue=''
    ++ export 'LESS_TERMCAP_us='
    ++ LESS_TERMCAP_us=''
    ++ export -f wcd
    ++ [[ C:\Documents and Settings\User == \C\:\\\U\s\e\r\s\\\j\a\r\e\d ]]
    ++ export GNUGCC=/cygdrive/g/GNU-GCC
    ++ GNUGCC=/cygdrive/g/GNU-GCC
    ++ alias 'stamp=export STAMP=`date +D%Y%m%d.T%H%M%S`; export LOGS=`pwd`/logs/${STAMP};  mkdir -pv ${LOGS}'
    ++ alias 'gcd=cd /cygdrive/g/GNU-GCC/toolchain-avr'
    ++ alias 'gcc=cd /cygdrive/g/GNU-GCC/toolchain-avr/gcc-build; stamp; ../gcc/libgcc/configure'
    ++ alias 'avr=gcd; stamp; (build_package-avr-gcc.bash "$STAMP" "$LOGS" 2>&1) | tee $LOGS/_package.log'
    ++ alias 'avo=gcd; stamp; (package-avr-gcc.bash 2>&1) | tee $LOGS/_package.log'
    ++ alias -p
    alias ..='cd ..'
    alias avo='gcd; stamp; (package-avr-gcc.bash 2>&1) | tee $LOGS/_package.log'
    alias avr='gcd; stamp; (build_package-avr-gcc.bash "$STAMP" "$LOGS" 2>&1) | tee $LOGS/_package.log'
    alias cls='tput reset'
    alias cp='cp -i'
    alias debug='set -o nounset; set -o xtrace'
    alias df='df -kTh'
    alias du='du -kh'
    alias gcc='cd /cygdrive/g/GNU-GCC/toolchain-avr/gcc-build; stamp; ../gcc/libgcc/configure'
    alias gcd='cd /cygdrive/g/GNU-GCC/toolchain-avr'
    alias h='history'
    alias j='jobs -l'
    alias la='ll -A'
    alias lc='ls -ltcr'
    alias libpath='echo -e ${LD_LIBRARY_PATH//:/\\n}'
    alias lk='ls -lSr'
    alias ll='ls -lv --group-directories-first'
    alias lm='ll |more'
    alias lr='ll -R'
    alias ls='ls -h --color'
    alias lt='ls -ltr'
    alias lu='ls -ltur'
    alias lx='ls -lXB'
    alias more='less'
    alias mv='mv -i'
    alias path='echo -e ${PATH//:/\\n}'
    alias popnullglob='$nullglob ; unset nullglob'
    alias pushnullglob='local nullglob=$(shopt -p nullglob) ; shopt -s nullglob'
    alias rm='rm -i'
    alias stamp='export STAMP=`date +D%Y%m%d.T%H%M%S`; export LOGS=`pwd`/logs/${STAMP};  mkdir -pv ${LOGS}'
    alias tree='tree -Csuh'
    alias which='type -a'

    User@hej ~
    $ shopt
    + shopt
    autocd          off
    cdable_vars     off
    cdspell         off
    checkhash       on
    checkjobs       off
    checkwinsize    on
    cmdhist         on
    compat31        off
    compat32        off
    compat40        off
    compat41        off
    compat42        off
    complete_fullquote      on
    direxpand       off
    dirspell        off
    dotglob         off
    execfail        off
    expand_aliases  on
    extdebug        off
    extglob         on
    extquote        on
    failglob        off
    force_fignore   on
    globstar        off
    globasciiranges off
    gnu_errfmt      off
    histappend      on
    histreedit      on
    histverify      on
    hostcomplete    on
    huponexit       off
    interactive_comments    on
    lastpipe        off
    lithist         off
    login_shell     on
    mailwarn        off
    no_empty_cmd_completion on
    nocaseglob      on
    nocasematch     off
    nullglob        off
    progcomp        on
    promptvars      on
    restricted_shell        off
    shift_verbose   off
    sourcepath      on
    xpg_echo        off

    User@hej ~
    $ set
    + set
    ALLUSERSPROFILE='C:\Documents and Settings\All Users'
    APPDATA='C:\Documents and Settings\User\Application Data'
    BASH=/bin/bash
    BASHOPTS=checkhash:checkwinsize:cmdhist:complete_fullquote:expand_aliases:extglob:extquote:force_fignore:histappend:histreedit:histverify:hostcomplete:interactive_comments:login_shell:no_empty_cmd_completion:nocaseglob:progcomp:promptvars:sourcepath
    BASH_ALIASES=()
    BASH_ARGC=()
    BASH_ARGV=()
    BASH_CMDS=()
    BASH_LINENO=()
    BASH_SOURCE=()
    BASH_VERSINFO=([0]="4" [1]="3" [2]="46" [3]="6" [4]="release" [5]="i686-pc-cygwin")
    BASH_VERSION='4.3.46(6)-release'
    CLIENTNAME=Console
    COLUMNS=132
    COMMONPROGRAMFILES='C:\Program Files\Common Files'
    COMPUTERNAME=HEJ
    COMSPEC='C:\WINDOWS\System32\CMD.EXE'
    CYGDRIVE=/cygdrive
    CYGWIN_HOME='C:\cygwin'
    CYG_SYS_BASHRC=1
    CommonAppData='C:\Documents and Settings\All Users\Application Data'
    CommonDesktop='C:\Documents and Settings\All Users\Desktop'
    CommonDocuments='C:\Documents and Settings\All Users\Documents'
    CommonFavorites='C:\Documents and Settings\All Users\Favorites'
    CommonMusic='C:\Documents and Settings\All Users\Documents\My Music'
    CommonPictures='C:\Documents and Settings\All Users\Documents\My Pictures'
    CommonTemplates='C:\Documents and Settings\All Users\Templates'
    CommonVideos='C:\Documents and Settings\All Users\Documents\My Videos'
    DIRSTACK=()
    DefaultUserProfile='C:\Documents and Settings\Default User'
    DevMgr_Show_Details='*'
    DevMgr_Show_NonPresent_Devices='*'
    EUID=197614
    EXECIGNORE='*.dll'
    FP_NO_HOST_CHECK=NO
    GNUGCC=/cygdrive/g/GNU-GCC
    GROUPS=()
    HISTFILE='/c/Documents and Settings/User/.bash_history'
    HISTFILESIZE=500
    HISTSIZE=500
    HOME=/cygdrive/g/GNU-GCC/home/User
    HOMEDRIVE=C:
    HOMEPATH='\Documents and Settings\User'
    HOSTNAME=hej
    HOSTTYPE=i686
    IFS=$' \t\n'
    IGNOREEOF=10
    INFOPATH=/usr/local/info:/usr/share/info:/usr/info
    JD2_HOME='C:\Documents and Settings\User\Local Settings\Application Data\JDownloader 2.0'
    LANG=en_US.UTF-8
    LESS=$'-i -w -s -z-4 -g -M -X -r -f -P%t?f%f \\\n:stdin .?pb%pb\\%:?lbLine %lb:?bbByte %bb:-...'
    LESSCHARSET=latin1
    LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-'
    LESS_TERMCAP_mb=$'\E[01;31m'
    LESS_TERMCAP_md=$'\E[01;31m'
    LESS_TERMCAP_me=$'\E[0m'
    LESS_TERMCAP_se=$'\E[0m'
    LESS_TERMCAP_so=$'\E[01;44;33m'
    LESS_TERMCAP_ue=$'\E[0m'
    LESS_TERMCAP_us=$'\E[01;32m'
    LINES=80
    LOGONSERVER='\\HEJ'
    MACHTYPE=i686-pc-cygwin
    MTPPKROOT='C:\WMSDK\MTPPK12\Responder'
    NUMBER_OF_PROCESSORS=2
    OLDPWD='/c/Documents and Settings/User'
    OPTERR=1
    OPTIND=1
    ORIGINAL_PATH='/usr/bin:/c:/c/tools:/c/WINDOWS/System32:/c/WINDOWS:/c/WINDOWS/System32/WBEM:/c/WINDOWS/system32/WindowsPowerShell/v1.0:/c/cgywin/bin:/c/MinGW/bin:/c/Documents and Settings/All Users/Application Data/Oracle/Java/javapath:/c/Program Files/rexx.org/Regina:/c/Program Files/rexx.org/THE'
    OS=Windows_NT
    OSTYPE=cygwin
    PAGER=less
    PATH='./://cygdrive/c/bin:/usr/local/bin:/usr/bin:/usr/bin:/c:/c/tools:/c/WINDOWS/System32:/c/WINDOWS:/c/WINDOWS/System32/WBEM:/c/WINDOWS/system32/WindowsPowerShell/v1.0:/c/cgywin/bin:/c/MinGW/bin:/c/Documents and Settings/All Users/Application Data/Oracle/Java/javapath:/c/Program Files/rexx.org/Regina:/c/Program Files/rexx.org/THE:/c/Documents and Settings/User'
    PATHEXT='.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.REX;.Rexx;.PSC1'
    PIPESTATUS=([0]="0")
    PPID=944
    PRINTER='HP LaserJet Professional P1606dn'
    PROCESSOR_ARCHITECTURE=x86
    PROCESSOR_IDENTIFIER='x86 Family 15 Model 6 Stepping 2, GenuineIntel'
    PROCESSOR_LEVEL=15
    PROCESSOR_REVISION=0602
    PROFILEREAD=true
    PROGRAMFILES='C:\Program Files'
    PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
    PS2='> '
    PS4='+ '
    PSModulePath='C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\'
    PWD=/cygdrive/g/GNU-GCC/home/User
    REGINA_HOME='C:\Program Files\rexx.org\Regina'
    REGINA_LANG=en
    REGINA_LANG_DIR='C:\Program Files\rexx.org\Regina'
    SESSIONNAME=Console
    SHELL=/bin/bash
    SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:ignoreeof:interactive-comments:monitor:noclobber:notify:nounset:xtrace
    SHLVL=1
    SYSTEMDRIVE=C:
    SYSTEMROOT='C:\WINDOWS'
    TEMP=/tmp
    TERM=xterm
    THE_HELP_FILE='C:\Program Files\rexx.org\THE\THE_Help.txt'
    THE_HOME_DIR='C:\Program Files\rexx.org\THE'
    THE_MACRO_PATH='C:\Program Files\rexx.org\THE\extras'
    TMP=/tmp
    TZ=America/New_York
    UID=197614
    USER=User
    USERDOMAIN=HEJ
    USERNAME=User
    USERPROFILE='C:\Documents and Settings\User'
    WINDIR='C:\WINDOWS'
    _=shopt
    _NT_SYMBOL_PATH='srv*c:\symbols*https://msdl.microsoft.com/download/symbols'
    profile_d ()
    {
        _LC_ALL_SET_="${LC_ALL+set}";
        _LC_SAVE_="${LC_ALL-null}";
        LC_ALL=C;
        if [ "${_LC_SAVE_}" = "null" ]; then
            for file in /etc/profile.d/*.$1;
            do
                [ -e "${file}" ] && . "${file}";
            done;
            unset LC_ALL;
        else
            for file in /etc/profile.d/*.$1;
            do
                [ -e "${file}" ] && LC_ALL="${_LC_SAVE_}" . "${file}";
            done;
            LC_ALL="${_LC_SAVE_}";
        fi;
        unset file;
        unset _LC_ALL_SET_;
        unset _LC_SAVE_
    }
    wcd ()
    {
        cd $(sed -e 's~\\~/~g' -e 's~c:~$CYGDRIVE/c~g' -e 's~g:~$CYGDRIVE/g~' <<< "$@")
    }

    User@hej ~
    $ mount
    + mount

Ctrl-c entered <------


    User@hej ~
    $

    User@hej ~
    $

    User@hej ~
    $ man mount
    + man mount
Ctrl-c entered <------


    User@hej ~
    $

DOS路径:

PATH=C:\cygwin\bin\;C:\;c:\tools;C:\WINDOWS\System32;C:\WINDOWS;C:\WINDOWS\System32\WBEM;C:\WINDOWS\system32\WindowsPowerShell\v1.0;C:\cgywin\bin;C:\MinGW\bin;C:\Documents and Settings\All Users\Application Data\Oracle\Java\javapath;C:\Program Files\rexx.org\Regina;C:\Program Files\rexx.org\THE

答案1

我通过向本地卷的 FSTAB 添加条目来“破坏”我的系统,如下所示:

# /etc/fstab
#
#    This file is read once by the first process in a Cygwin process tree.
#    To pick up changes, restart all Cygwin processes.  For a description
#    see https://cygwin.com/cygwin-ug-net/using.html#mount-table

# This is default anyway:
none /cygdrive cygdrive binary,posix=0,user 0 0

c:/ /c ntfs text,posix=0 0 0
d:/ /d ntfs text,posix=0 0 0
f:/ /f ntfs text,posix=0 0 0
g:/ /g ntfs text,posix=0 0 0

我通过将 fstab 更改为“修复”它:

none /cygdrive cygdrive binary,posix=0,user 0 0
none /tmp usertemp binary,posix=0 0 0

c:/  /c  ntfs binary,posix=0,cygexec 0 0
d:/  /d  ntfs binary,posix=0,cygexec 0 0
f:/  /f  ntfs binary,posix=0,cygexec 0 0
g:/  /g  ntfs binary,posix=0,cygexec 0 0

我认为发生的情况是,通过不将 4 个驱动器(c、d、f、g)安装为“exec”,每次 cygwin 搜索外部时,它都会打开并读取大量文件来查找“magic”字节”查看该文件是否是可执行文件。

与此同时,mintty 正在缓冲我作为“提前输入”输入的内容,直到我按 ctrl-c 退出,从而终止仍在运行的对我的命令的搜索。

通过将“cygexec”添加到选项中,搜索现在仅参考目录中的可执行标志,并全速运行。

相关内容