主要编辑:经过更多调查,我现在相信问题不在 .bash_profile 中,而是在每个命令之后运行的某些内容中。在每个命令之后我都会得到一条神秘的痕迹——甚至是一个新行。我不知道该怎么称呼这个“东西”,如果有人能告诉我,我将不胜感激。另外,我应该取消这个问题并发布一个新问题吗?
我最初在 stackoverflow 上发布,但有人建议我应该在这里发布,所以这里是:
我使用的是 macOS 10.12.1
我很少使用终端和 bash,但大约 6 周前发生了巨大的变化。下面是我的 .bash_profile,它多年来一直没有变化,下面是我打开终端窗口时得到的奇怪的东西。我认为问题出在我的 .bash_profile 中,但也可能在其他地方。
我只是无法解决这个问题,非常感谢任何帮助。
.bash_profile
:
set -x
echo "Running ~/.bash_profile"
red=$(tput setaf 1)
none=$(tput sgr0)
PS1='\[$red\]***\t \! \w>\[$none\]' # Using \W will provide just basename
#echo PS1=$PS1
PS4=' $LINENO: ' # Set bash script prompt to line number of script
export PS4
alias cc="/usr/bin/llvm-gcc-4.2"
DEV_INC=/Developer/SDKs/MacOSX10.5.sdk/usr/include
#temp="/Developer/Tools:/Developer/Applications:"${PATH}:~/bin::
temp="/Developer/Tools:/Developer/Applications:"${PATH}:/Application s/MacVim.app/Contents/MacOS:~/bin::
PATH=$temp
#echo PATH=$PATH
#include_path=.:/usr/include/:
#echo include_path=$include_path
echo BASH_VERSION=$BASH_VERSION
. ~/MYFUNCTIONS
export -f mygetopts isoption
compgen -A function # List all functions
打开新的 bash 窗口的痕迹:
Last login: Wed Nov 30 18:07:37 on ttys003
+ echo 'Running ~/.bash_profile'
Running ~/.bash_profile
++ tput setaf 1
cd ~/work
+ red=''
++ tput sgr0
+ none=''
+ PS1='\[$red\]***\t \! \w \[$none\]'
+ PS4=' $LINENO: '
10: export PS4
11: alias cc=/usr/bin/llvm-gcc-4.2
12: DEV_INC=/Developer/SDKs/MacOSX10.5.sdk/usr/include
14: temp=/Developer/Tools:/Developer/Applications:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/MacVim.app/Contents/MacOS:/Users/XXXXX/bin::
15: PATH=/Developer/Tools:/Developer/Applications:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/MacVim.app/Contents/MacOS:/Users/XXXXX/bin::
19: echo 'BASH_VERSION=3.2.57(1)-release'
BASH_VERSION=3.2.57(1)-release
21: . /Users/XXXXX/MYFUNCTIONS
22: export -f mygetopts isoption
23: compgen -A function
isoption
mygetopts
shell_session_delete_expired
shell_session_history_allowed
shell_session_history_check
shell_session_history_enable
shell_session_save
shell_session_save_history
shell_session_update
update_terminal_cwd
0: shell_session_history_check
1: '[' 0 -eq 0 ']'
2: SHELL_SESSION_DID_HISTORY_CHECK=1
3: shell_session_history_allowed
2: '[' -n /Users/XXXXX/.bash_history ']'
5: local allowed=0
6: shopt -q histappend
6: '[' -n '' ']'
9: allowed=1
11: '[' 1 -eq 1 ']'
12: return 0
47: shell_session_history_enable
1: umask 077
1: touch /Users/XXXXX/.bash_sessions/AC4138F0-CE17-4189-80E4-29F987640EBB.historynew
2: HISTFILE=/Users/XXXXX/.bash_sessions/AC4138F0-CE17-4189-80E4-29F987640EBB.historynew
3: SHELL_SESSION_HISTORY=1
28: '[' 'shell_session_history_check; update_terminal_cwd' = shell_session_history_check ']'
30: [[ shell_session_history_check; update_terminal_cwd =~ (.*)(; *shell_session_history_check *| * shell_session_history_check *; *)(.*) ]]
31: PROMPT_COMMAND=update_terminal_cwd
0: update_terminal_cwd
5: local url_path=
9: local i ch hexch LC_CTYPE=C LC_ALL=
10: (( i = 0 ))
19: (( i < 16 ))
11: ch=/
12: [[ / =~ [/._~A-Za-z0-9-] ]]
13: url_path+=/
19: (( ++i ))
19: (( i < 16 ))
11: ch=U
12: [[ U =~ [/._~A-Za-z0-9-] ]]
13: url_path+=U
19: (( ++i ))
19: (( i < 16 ))
11: ch=s
12: [[ s =~ [/._~A-Za-z0-9-] ]]
13: url_path+=s
19: (( ++i ))
19: (( i < 16 ))
11: ch=e
12: [[ e =~ [/._~A-Za-z0-9-] ]]
13: url_path+=e
19: (( ++i ))
19: (( i < 16 ))
11: ch=r
12: [[ r =~ [/._~A-Za-z0-9-] ]]
13: url_path+=r
19: (( ++i ))
19: (( i < 16 ))
11: ch=s
12: [[ s =~ [/._~A-Za-z0-9-] ]]
13: url_path+=s
19: (( ++i ))
19: (( i < 16 ))
11: ch=/
12: [[ / =~ [/._~A-Za-z0-9-] ]]
13: url_path+=/
19: (( ++i ))
19: (( i < 16 ))
11: ch=j
12: [[ j =~ [/._~A-Za-z0-9-] ]]
13: url_path+=j
19: (( ++i ))
19: (( i < 16 ))
11: ch=i
12: [[ i =~ [/._~A-Za-z0-9-] ]]
13: url_path+=i
19: (( ++i ))
19: (( i < 16 ))
11: ch=m
12: [[ m =~ [/._~A-Za-z0-9-] ]]
13: url_path+=m
19: (( ++i ))
19: (( i < 16 ))
11: ch=s
12: [[ s =~ [/._~A-Za-z0-9-] ]]
13: url_path+=s
19: (( ++i ))
19: (( i < 16 ))
11: ch=l
12: [[ l =~ [/._~A-Za-z0-9-] ]]
13: url_path+=l
19: (( ++i ))
19: (( i < 16 ))
11: ch=a
12: [[ a =~ [/._~A-Za-z0-9-] ]]
13: url_path+=a
19: (( ++i ))
19: (( i < 16 ))
11: ch=g
12: [[ g =~ [/._~A-Za-z0-9-] ]]
13: url_path+=g
19: (( ++i ))
19: (( i < 16 ))
11: ch=e
12: [[ e =~ [/._~A-Za-z0-9-] ]]
13: url_path+=e
19: (( ++i ))
19: (( i < 16 ))
11: ch=r
12: [[ r =~ [/._~A-Za-z0-9-] ]]
13: url_path+=r
19: (( ++i ))
19: (( i < 16 ))
23: printf '\e]7;%s\a' file://groksiMac-804.local/Users/XXXXX
***18:34:36 500 ~ cd ~/work
1: cd /Users/XXXXX/work
1: update_terminal_cwd
5: local url_path=
9: local i ch hexch LC_CTYPE=C LC_ALL=
10: (( i = 0 ))
19: (( i < 21 ))
11: ch=/
12: [[ / =~ [/._~A-Za-z0-9-] ]]
13: url_path+=/
19: (( ++i ))
19: (( i < 21 ))
11: ch=U
12: [[ U =~ [/._~A-Za-z0-9-] ]]
13: url_path+=U
19: (( ++i ))
19: (( i < 21 ))
11: ch=s
12: [[ s =~ [/._~A-Za-z0-9-] ]]
13: url_path+=s
19: (( ++i ))
19: (( i < 21 ))
11: ch=e
12: [[ e =~ [/._~A-Za-z0-9-] ]]
13: url_path+=e
19: (( ++i ))
19: (( i < 21 ))
11: ch=r
12: [[ r =~ [/._~A-Za-z0-9-] ]]
13: url_path+=r
19: (( ++i ))
19: (( i < 21 ))
11: ch=s
12: [[ s =~ [/._~A-Za-z0-9-] ]]
13: url_path+=s
19: (( ++i ))
19: (( i < 21 ))
11: ch=/
12: [[ / =~ [/._~A-Za-z0-9-] ]]
13: url_path+=/
19: (( ++i ))
19: (( i < 21 ))
11: ch=j
12: [[ j =~ [/._~A-Za-z0-9-] ]]
13: url_path+=j
19: (( ++i ))
19: (( i < 21 ))
11: ch=i
12: [[ i =~ [/._~A-Za-z0-9-] ]]
13: url_path+=i
19: (( ++i ))
19: (( i < 21 ))
11: ch=m
12: [[ m =~ [/._~A-Za-z0-9-] ]]
13: url_path+=m
19: (( ++i ))
19: (( i < 21 ))
11: ch=s
12: [[ s =~ [/._~A-Za-z0-9-] ]]
13: url_path+=s
19: (( ++i ))
19: (( i < 21 ))
11: ch=l
12: [[ l =~ [/._~A-Za-z0-9-] ]]
13: url_path+=l
19: (( ++i ))
19: (( i < 21 ))
11: ch=a
12: [[ a =~ [/._~A-Za-z0-9-] ]]
13: url_path+=a
19: (( ++i ))
19: (( i < 21 ))
11: ch=g
12: [[ g =~ [/._~A-Za-z0-9-] ]]
13: url_path+=g
19: (( ++i ))
19: (( i < 21 ))
11: ch=e
12: [[ e =~ [/._~A-Za-z0-9-] ]]
13: url_path+=e
19: (( ++i ))
19: (( i < 21 ))
11: ch=r
12: [[ r =~ [/._~A-Za-z0-9-] ]]
13: url_path+=r
19: (( ++i ))
19: (( i < 21 ))
11: ch=/
12: [[ / =~ [/._~A-Za-z0-9-] ]]
13: url_path+=/
19: (( ++i ))
19: (( i < 21 ))
11: ch=w
12: [[ w =~ [/._~A-Za-z0-9-] ]]
13: url_path+=w
19: (( ++i ))
19: (( i < 21 ))
11: ch=o
12: [[ o =~ [/._~A-Za-z0-9-] ]]
13: url_path+=o
19: (( ++i ))
19: (( i < 21 ))
11: ch=r
12: [[ r =~ [/._~A-Za-z0-9-] ]]
13: url_path+=r
19: (( ++i ))
19: (( i < 21 ))
11: ch=k
12: [[ k =~ [/._~A-Za-z0-9-] ]]
13: url_path+=k
19: (( ++i ))
19: (( i < 21 ))
23: printf '\e]7;%s\a' file://groksiMac-804.local/Users/XXXXX/work
***18:34:36 501 ~/work
答案1
set -x
从您的顶部删除~/.bash_profile
。set -x
导致 bash 在运行之前输出它运行的每个命令。从 bash 手册页:
-x After expanding each simple command, for command, case command, select
command, or arithmetic for command, display the expanded value of PS4,
followed by the command and its expanded arguments or associated word
list.
答案2
经过更多调查后,我已将问题确定为 PS1 变量。我一直在使用 PS1='[$red]***\t ! \w>[$none]' 已经使用了很多年,但它不再起作用,并且会在从命令行输入的每个 bash 命令上产生很长的跟踪。将其注释掉会导致跟踪停止。