我一直在寻找这个答案,也许这是一条我不知道的死胡同。我正在运行Ubuntu20.04,我现在拥有这个bash_profile:
export MAG_DIR="/var/www/html/magento-2"
export NGINX_ERR="/var/log/nginx/error.log"
export MAG_ERR="/var/www/html/magento-2/var/log/system.log"
export XDEBUG_LOG="/var/log/xdebug/xdebug.log"
export PHP_FPM_CONF="/etc/php/7.3/fpm/php.ini"
export PHP_CLI_CONF="/etc/php/7.3/cli/php.ini"
export PHP_LOG="/tmp/php-error.log"
function wgrep () {
grep -nA 3 -B 3 $1;
}
function findfirst () {
find $1 -name $2 | head -n 1
}
function catfirst () {
cat $(find $1 -name $2 | head -n 2)
}
function t30 {
tail -fn 30 $1;
}
function fac {
git fetch && git checkout $1;
}
#if [ -f ~/.bashrc ]; then
# . ~/.bashrc
#fi
if [ -f ~/.bash_vars ]; then
. ~/.bash_vars
fi
export PS1="\D{%H:%M:%S} \[\e]0;\u@\h: \w\a\] ${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
#local setup
[ ! -f $PHP_LOG ] && touch $PHP_LOG
chmod 777 $PHP_LOG
cd $MAG_DIR
clear我希望将最后一行迁移到单独的脚本中,该脚本只在第一次创建时才运行。
我喜欢在工作时调整我的/.bash_profile,它来源于~/.bashrc,所以如果我在~/..bash_profile中进行修改,并且希望看到这些更改,目前我将被引导回我的dev目录。此外,它还将对日志文件等文件进行冗余更改。这些登录“安装”操作可能会随着时间的推移而改变。
我知道.bash_login存在,但我似乎无法让它为我工作。我将我的终端首选项设置为“以登录方式运行命令”,或者不管设置是什么,它都会忽略我的~/.bash_profile (我猜这可能是有意的行为)。
p.s:‘~/..bash_vars包含随机变量,我希望从env到env或保存一些秘密,因为这个bash_profile是版本化的。
发布于 2020-12-30 18:53:09
从OP问题来看,目标是让.bash_profile的尾部只在初始的shell上执行,而不是在子shell上执行。一个可能的解决方案是跟踪导出变量中的一次性执行。
if [ ! "$FIRST_TIME" ] ; then
export FIRST_TIME=YES
[ ! -f $PHP_LOG ] && touch $PHP_LOG
chmod 777 $PHP_LOG
cd $MAG_DIR
clear
fi在本例中,“.bashrc”正在查找..bash_profile‘,受"FIRST_TIME“保护的命令将不会在交互式子subshell上执行。
https://stackoverflow.com/questions/65505279
复制相似问题