bashrc路径获取重复的条目

bashrc路径获取重复的条目,bash,path,cygwin,Bash,Path,Cygwin,我在cygwin$HOME/.bashrc中设置了以下变量 PATH=/bin:/usr/sbin:"/cygdrive/c/Program Files/Java/jdk1.6.0_26/bin":$PATH 问题是,当我登录并执行.bashrc时,我会得到如下启动副本: Dragos@dragos ~ $ echo $PATH | tr ':' '\n' /bin /usr/sbin /cygdrive/c/Program Files/Java/jdk1.6.0_26/bin /bin /u

我在cygwin$HOME/.bashrc中设置了以下变量

PATH=/bin:/usr/sbin:"/cygdrive/c/Program Files/Java/jdk1.6.0_26/bin":$PATH
问题是,当我登录并执行.bashrc时,我会得到如下启动副本:

Dragos@dragos ~
$ echo $PATH | tr ':' '\n'
/bin
/usr/sbin
/cygdrive/c/Program Files/Java/jdk1.6.0_26/bin
/bin
/usr/sbin
/cygdrive/c/Program Files/Java/jdk1.6.0_26/bin
/usr/local/bin
/usr/bin
/cygdrive/c/WINDOWS
/cygdrive/c/WINDOWS/system32
/cygdrive/c/WINDOWS/System32/Wbem
/cygdrive/c/curl
/
/cygdrive/c/gnupg
/cygdrive/c/Progra~1/cvsnt
/cygdrive/c/Progra~1/GNU/WinCvs 2.0
/cygdrive/c/Progra~1/Notepad++
/cygdrive/c/Progra~1/PuTTY
/cygdrive/c/Progra~1/WinSCP
/cygdrive/c/Python26
/cygdrive/c/Python26/Lib/site-packages/PyQt4/bin
/cygdrive/c/Python26/Scripts
/usr/bin
/usr/lib/lapack
有人知道这是什么原因吗

这是我的
.bashrc

$ cat ~/.bashrc    
# base-files version 3.7-1

# To pick up the latest recommended .bashrc content,
# look in /etc/defaults/etc/skel/.bashrc

# Modifying /etc/skel/.bashrc directly will prevent
# setup from updating it.

# The copy in your home directory (~/.bashrc) is yours, please
# feel free to customise it to create a shell
# environment to your liking.  If you feel a change
# would be benificial to all, please feel free to send
# a patch to the cygwin mailing list.

# User dependent .bashrc file

# Shell Options
# #############

# See man bash for more options...

# Don't wait for job termination notification
# set -o notify

# Don't use ^D to exit
# set -o ignoreeof

# Use case-insensitive filename globbing
# shopt -s nocaseglob

# Make bash append rather than overwrite the history on disk
# shopt -s histappend

# When changing directory small typos can be ignored by bash
# for example, cd /vr/lgo/apaache would find /var/log/apache
# shopt -s cdspell


# Completion options
# ##################

# These completion tuning parameters change the default behavior of bash_completion:

# Define to access remotely checked-out files over passwordless ssh for CVS
# COMP_CVS_REMOTE=1

# Define to avoid stripping description in --option=description of './configure --help'
# COMP_CONFIGURE_HINTS=1

# Define to avoid flattening internal contents of tar files
# COMP_TAR_INTERNAL_PATHS=1

# If this shell is interactive, turn on programmable completion enhancements.
# Any completions you add in ~/.bash_completion are sourced last.
# case $- in
#   *i*) [[ -f /etc/bash_completion ]] && . /etc/bash_completion ;;
# esac


# History Options
# ###############

# Don't put duplicate lines in the history.
# export HISTCONTROL="ignoredups"

# Ignore some controlling instructions
# export HISTIGNORE="[   ]*:&:bg:fg:exit"

# Whenever displaying the prompt, write the previous line to disk
# export PROMPT_COMMAND="history -a"


# Aliases
# #######

# Some example alias instructions
# If these are enabled they will be used instead of any instructions
# they may mask.  For example, alias rm='rm -i' will mask the rm
# application.  To override the alias instruction use a \ before, ie
# \rm will call the real rm not the alias.

# Interactive operation...
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'

# Default to human readable figures
# alias df='df -h'
# alias du='du -h'

# Misc :)
# alias less='less -r'                          # raw control characters
# alias whence='type -a'                        # where, of a sort
# alias grep='grep --color'                     # show differences in colour

# Some shortcuts for different directory listings
alias ls='ls -hF --color=tty'                 # classify files in colour
# alias dir='ls --color=auto --format=vertical'
# alias vdir='ls --color=auto --format=long'
# alias ll='ls -l'                              # long list
# alias la='ls -A'                              # all but . and ..
# alias l='ls -CF'                              #

# Functions
# #########

# Some example functions
# function settitle() { echo -ne "\e]2;$@\a\e]1;$@\a"; }

# Notepad++ function
# Pass in a UNIX path
# Starts notepad++ given a UNIX path argument
function notepadpp() { 
  local notepadUnixPath="/cygdrive/c/Program Files/Notepad++/notepad++.exe"
  #local notepadArgPath=$(eval $(echo cygpath -w -a "$*"))
  local notepadArgPath=`cygpath -w -a "$*"`
  "$notepadUnixPath" -multiInst "$notepadArgPath" &
}

alias notepad++=notepadpp

# Explorer function
# Pass in a UNIX path
# Starts explorer given a UNIX path argument
function explorer() { 
  local explorerArgPath=`cygpath -w -a "$*"`
  cmd /C start "" "$explorerArgPath" &
}

alias vi=vim

# Change filename starting with prefix string to another prefix string
alias mvprefix='$HOME/mvprefix.sh'

# Change filename ending with suffix string to another suffix string
alias mvsuffix='$HOME/mvsuffix.sh'

# Change filename ending with suffix string to a string prefixed with todays date
alias todaysuffix='$HOME/todaysuffix.sh'

# Generate secure passwords by default 
alias pwgen='pwgen -y -c -s -n'

export INPUTRC=$HOME/.inputrc
export EDITOR=vim
export PATH=/bin:/usr/sbin:"/cygdrive/c/Program Files/Java/jdk1.6.0_26/bin":$PATH

# Overwrite DOS env variable APPDATA with our own for installing perl CPANPLUS
export APPDATA=$HOME
这是我的
.bash\u档案

$ cat .bash_profile
# base-files version 3.7-1

# To pick up the latest recommended .bash_profile content,
# look in /etc/defaults/etc/skel/.bash_profile

# Modifying /etc/skel/.bash_profile directly will prevent
# setup from updating it.

# The copy in your home directory (~/.bash_profile) is yours, please
# feel free to customise it to create a shell
# environment to your liking.  If you feel a change
# would be benifitial to all, please feel free to send
# a patch to the cygwin mailing list.

# ~/.bash_profile: executed by bash for login shells.

# source the system wide bashrc if it exists
if [ -e /etc/bash.bashrc ] ; then
  source /etc/bash.bashrc
fi

# source the users bashrc if it exists
if [ -e "${HOME}/.bashrc" ] ; then
  source "${HOME}/.bashrc"
fi

# Set PATH so it includes user's private bin if it exists
# if [ -d "${HOME}/bin" ] ; then
#   PATH=${HOME}/bin:${PATH}
# fi

# Set MANPATH so it includes users' private man if it exists
# if [ -d "${HOME}/man" ]; then
#   MANPATH=${HOME}/man:${MANPATH}
# fi

# Set INFOPATH so it includes users' private info if it exists
# if [ -d "${HOME}/info" ]; then
#   INFOPATH=${HOME}/info:${INFOPATH}
# fi
这是我的
/etc/bash.bashrc

$ cat /etc/bash.bashrc
# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software.
# If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.

# base-files version 4.1-1

# /etc/bash.bashrc: executed by bash(1) for interactive shells.

# The latest version as installed by the Cygwin Setup program can
# always be found at /etc/defaults/etc/bash.bashrc

# Modifying /etc/bash.bashrc directly will prevent
# setup from updating it.

# System-wide bashrc file

# Check that we haven't already been sourced.
([[ -z ${CYG_SYS_BASHRC} ]] && CYG_SYS_BASHRC="1") || return

# If not running interactively, don't do anything
[[ "$-" != *i* ]] && return

# Set a default prompt of: user@host and current_directory
PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '

# Uncomment to use the terminal colours set in DIR_COLORS
# eval "$(dircolors -b /etc/DIR_COLORS)"
结果:

Dragos@dragos ~
$ echo $PATH | tr ':' '\n'
/cygdrive/c/Program Files/Java/jdk1.6.0_26/bin
/cygdrive/c/Program Files/Java/jdk1.6.0_26/bin
/usr/local/bin
/usr/bin
/cygdrive/c/WINDOWS
/cygdrive/c/WINDOWS/system32
/cygdrive/c/WINDOWS/System32/Wbem
/cygdrive/c/curl
/
/cygdrive/c/gnupg
/cygdrive/c/Progra~1/cvsnt
/cygdrive/c/Progra~1/GNU/WinCvs 2.0
/cygdrive/c/Progra~1/Notepad++
/cygdrive/c/Progra~1/PuTTY
/cygdrive/c/Progra~1/WinSCP
/cygdrive/c/Python26
/cygdrive/c/Python26/Lib/site-packages/PyQt4/bin
/cygdrive/c/Python26/Scripts
/usr/bin
/usr/lib/lapack
所以。。。为什么要复制

增编:

我发现我在
C:\cygwin\cygwin.bat中执行了两次bash
原因是我有一个上下文菜单命令来“在这里打开Bash”,这个命令通过了
C:\cygwin\cygwin.bat的起始路径

@echo off

C:

set PATH=%PATH%;C:\cygwin\bin

REM SHELL needed for any screen instances started from bash
set SHELL=/bin/bash
set HOME=C:\cygwin\home\Dragos
set HOMEDRIVE=C:
set HOMEPATH=\cygwin\home\Dragos

REM 

if not [%1]==[] (
  C:\cygwin\bin\cygpath %1 > tmpFile
  set /p startingpath= < tmpFile
  del tmpFile
)

if "%startingpath%"=="" start C:\cygwin\bin\mintty.exe --icon /Cygwin-Terminal.ico --size 140,50 --exec /bin/bash --login
if not "%startingpath%"=="" start C:\cygwin\bin\mintty.exe --icon /Cygwin-Terminal.ico --size 140,50 --exec /bin/bash --noprofile --norc --login -c "cd '%startingpath%'; exec /bin/bash -rcfile ~/.bashrc"

exit
这是我的
C:\cygwin\cygwin.bat

@echo off

C:

set PATH=%PATH%;C:\cygwin\bin

REM SHELL needed for any screen instances started from bash
set SHELL=/bin/bash
set HOME=C:\cygwin\home\Dragos
set HOMEDRIVE=C:
set HOMEPATH=\cygwin\home\Dragos

REM 

if not [%1]==[] (
  C:\cygwin\bin\cygpath %1 > tmpFile
  set /p startingpath= < tmpFile
  del tmpFile
)

if "%startingpath%"=="" start C:\cygwin\bin\mintty.exe --icon /Cygwin-Terminal.ico --size 140,50 --exec /bin/bash --login -c "exec /bin/bash -rcfile ~/.bashrc"
if not "%startingpath%"=="" start C:\cygwin\bin\mintty.exe --icon /Cygwin-Terminal.ico --size 140,50 --exec /bin/bash --login -c "cd '%startingpath%'; exec /bin/bash -rcfile ~/.bashrc"
exit

我没有安装Cygwin,也没有Windows机器,所以我无法向您提供大量详细信息

查看
manbash
页面是否可以帮助您。在普通BASH中,
/etc/profile
/etc/bashrc
$HOME/.BASH\u profile
$HOME/.bashrc
,有时还有
$HOME/.profile
都会被读入,这取决于这是否是登录shell。Cygwin在
/etc
目录中有自己的特殊版本。然而,还有其他脚本会被调用,并且会影响您的Cygwin环境。例如,有一些特殊的脚本可以导入Windows环境变量,包括
%PATH%

在Cygwin中,默认设置是将Windows
%PATH%
变量作为Cygwin路径的一部分。它实际上是所有Windows环境变量的一般导入(根据安装情况,
\
有时会转换为
/
并使用短目录名)

如果为Cygwin命令行打开xterm窗口而不是标准的windows控制台窗口,则还必须检查xserve脚本(或其名称),因为这也会将大量内容导入Cygwin环境

我以前使用过Cygwin,每次使用Cygwin时,我都会发现自己在追查这些事情,还有一些其他问题:例如,默认的Kornshell加载环境脚本中有一个bug。我相信它们有一个文字“^G”而不是Ctrl-G,或者可能是另一个控制字符。我不记得了。我只知道每次安装Cygwin环境时,我都会花一两个小时清理它。我喜欢Cygwin,但也会很痛苦


很抱歉,我无法为您提供更具体的说明。

只需将
路径设置为您喜欢的任何位置(不参考
$PATH
)。无论如何,您不应该相信一些随机系统管理员认为是好的
路径的
路径。在shell的最后一个源文件中执行此操作。

在更新之前,您是否检查过这些路径不在您的路径中?是的。不在那里。这就是我为他们做准备的原因。奇怪。我也是盲人;你们的出口线在哪里?我在您的.bashrc或.bash_配置文件中没有看到它。我的.bash\u配置文件只是做了一个
PATH=
来预先设置我需要的那些。原始的.bashrc是
PATH=
。我将它改为
export PATH=
,认为它可以解决复制问题。我将为我的
~/.bashrc
添加
~/.bashrc
的完整源代码,并将其从
导出路径=
更改回原始
路径=
。发现这确实是由于我对
C:\cygwin\cygwin.bat进行了自定义,以允许Windows上下文菜单选项
在Bash中打开当前目录
谢谢Jens。我发现在
C:\cygwin\cygwin.bat
中通过
--exec
mintty
调用它时,我需要将
--noprofile--norc
传递给
bash
bash
本身通过
-c
标志调用命令行,该标志允许我在启动另一个内部
bash
之前
cd
到传入的路径。内部的
bash
可以执行
.bash\u配置文件
.bashrc
@echo off

C:

set PATH=%PATH%;C:\cygwin\bin

REM SHELL needed for any screen instances started from bash
set SHELL=/bin/bash
set HOME=C:\cygwin\home\Dragos
set HOMEDRIVE=C:
set HOMEPATH=\cygwin\home\Dragos

REM 

if not [%1]==[] (
  C:\cygwin\bin\cygpath %1 > tmpFile
  set /p startingpath= < tmpFile
  del tmpFile
)

if "%startingpath%"=="" start C:\cygwin\bin\mintty.exe --icon /Cygwin-Terminal.ico --size 140,50 --exec /bin/bash --login
if not "%startingpath%"=="" start C:\cygwin\bin\mintty.exe --icon /Cygwin-Terminal.ico --size 140,50 --exec /bin/bash --noprofile --norc --login -c "cd '%startingpath%'; exec /bin/bash -rcfile ~/.bashrc"

exit