您的位置:首页 > 博客中心 > 网络系统 >

搞定mac的bashrc

时间:2022-04-03 14:16

 

  2015-03-11 14:16:26 1、根据这篇文章:


简单的说就是:
.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

Mac OS X — an exception

An exception to the terminal window guidelines is Mac OS X’s Terminal.app, which runs a login shell by default for each new terminal window, calling .bash_profile instead of .bashrc. Other GUI terminal emulators may do the same, but most tend not to.

而糟糕的是,MAC是一个例外,它会执行bash_profile,但不会去管.bashrc

===============================
2、好了,解决方案是

编辑一下.bash_profile:

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi
===============================

3、加上最需要的两个命令
alias ll=‘ls -lG‘
alias ls=‘ls -G‘
alias rm=‘rm -i‘
alias cp=‘cp -i‘
alias mv=‘mv -i‘

export PATH="/usr/local/share/npm/bin:$PATH"
export NODE_PATH=/usr/local/share/npm/lib/node_modules
export PYTHONPATH=/usr/local/lib/python3.3/site-packages

一个是ll,因为用习惯了centos所以ll很好用,ls也加上color。剩下的是两个PATH

===============================

4、总得来说就是,你需要在bash_profile里写入
CLICOLOR=1
LSCOLORS=gxfxcxdxbxegedabagacad
export PS1=‘\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ ‘
#enables colorfor iTerm
export TERM=xterm-color

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

-----------------------------
然后在bashrc里写入

alias ll=‘ls -lG‘
alias ls=‘ls -G‘
alias rm=‘rm -i‘
alias cp=‘cp -i‘
alias mv=‘mv -i‘   2015-03-11 14:16:26 1、根据这篇文章:


简单的说就是:
.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

Mac OS X — an exception

An exception to the terminal window guidelines is Mac OS X’s Terminal.app, which runs a login shell by default for each new terminal window, calling .bash_profile instead of .bashrc. Other GUI terminal emulators may do the same, but most tend not to.

而糟糕的是,MAC是一个例外,它会执行bash_profile,但不会去管.bashrc

===============================
2、好了,解决方案是

编辑一下.bash_profile:

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi
===============================

3、加上最需要的两个命令
alias ll=‘ls -lG‘
alias ls=‘ls -G‘
alias rm=‘rm -i‘
alias cp=‘cp -i‘
alias mv=‘mv -i‘

export PATH="/usr/local/share/npm/bin:$PATH"
export NODE_PATH=/usr/local/share/npm/lib/node_modules
export PYTHONPATH=/usr/local/lib/python3.3/site-packages

一个是ll,因为用习惯了centos所以ll很好用,ls也加上color。剩下的是两个PATH

===============================

4、总得来说就是,你需要在bash_profile里写入
CLICOLOR=1
LSCOLORS=gxfxcxdxbxegedabagacad
export PS1=‘\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ ‘
#enables colorfor iTerm
export TERM=xterm-color

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

-----------------------------
然后在bashrc里写入

alias ll=‘ls -lG‘
alias ls=‘ls -G‘
alias rm=‘rm -i‘
alias cp=‘cp -i‘
alias mv=‘mv -i‘

 

 

之前在服务器上的一些 bash 的操作习惯想在 mac 上保留,比如在跳板机上登陆服务器的命令,我在服务器上把命令作了别名保存这样我就可以简短的命令键入后就可以登陆到服务器.

比如在.bashrc 文件添加如下内容,脚本中的 login.sh 是自己写的登陆脚本.脚本会根据输入参数来区分登陆的环境.然后再根据另外的一个参数来选取登陆机器.

alias beta=‘~/login.sh beta‘
alias prod="~/login.sh prod"

然后使用 source 命令更新资源文件

source .bashrc

然后就可以使用如下命令

beta machineNameKeyWords

现在我需要把此脚本应用到 Mac 机器的 bash 上.发现 mac 上并没有这么一个.bashrc 文件,而且发现 mac 上的一些自定义的别名是存储在了.bash_profile 文件中.如当初遇到的

Mac OS X 是基于 FreeBSD 的,所以一些工具 ls, top 等都是 BSD 那一套,ls 不是 GNU ls,所以即使 Terminal/iTerm2 配置了颜色,但是在 Mac 上敲入 ls 命令也不会显示高亮,可以通过安装 coreutils 来解决(brew install coreutils),不过如果对 ls 颜色不挑剔的话有个简单办法就是在 .bash_profile 里输出 CLICOLOR=1:

链接地址:http://www.vpsee.com/2013/09/use-the-solarized-color-theme-on-mac-os-x-terminal/  

http://www.douban.com/note/321472256/

简单的说就是:

.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

 

Mac OS X — an exception

 

An exception to the terminal window guidelines is Mac OS X’s Terminal.app, which runs a login shell by default for each new terminal window, calling .bash_profile instead of .bashrc. Other GUI terminal emulators may do the same, but most tend not to.

 

而糟糕的是,MAC是一个例外,它会执行bash_profile,但不会去管.bashrc

因此你可以看到一般在要加 bash 的配置的地方,教程里面都使用的是.bash_profile 的配置.而不是说修改这个 .bashrc 文件.造成这些区别的原因是 Mac 的 bash 是一个 loginbash,loginbash会加载的是.bash_profile 不会加载.bashrc 文件.因此我们要做的就是

 

 

 

 

 

 

 

 

 

 

 

 

 

参考文献:

login-bash 与nonlogin-bash 的区别:http://www.cnblogs.com/qcly/p/3273373.html

http://my.oschina.net/yunyue/blog/108399

 

本类排行

今日推荐

热门手游