我尝试在我的环境中启动一个新的 shell,但bash
命令有问题:
$ bash
bash: command substitution: line 1: syntax error near unexpected token `then'
'ash: command substitution: line 1: `print -n "`logname`@`hostname`:$(tput sgr0)";if [[ "${PWD#$HOME}" != "$PWD" ]] then; print -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "
bash: command substitution: line 1: syntax error near unexpected token `then'
bash: command substitution: line 1: `print -n "`logname`@`hostname`:$(tput sgr0)";if [[ "${PWD#$HOME}" != "$PWD" ]] then; print -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "'
然后我就无法逃脱
$ ")^C
bash: command substitution: line 2: syntax error near unexpected token `then'
'ash: command substitution: line 2: `print -n "`logname`@`hostname`:$(tput sgr0)";if [[ "${PWD#$HOME}" != "$PWD" ]] then; print -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "
bash: command substitution: line 1: syntax error near unexpected token `then'
bash: command substitution: line 1: `print -n "`logname`@`hostname`:$(tput sgr0)";if [[ "${PWD#$HOME}" != "$PWD" ]] then; print -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "'
并且必须留下外壳 - 我想这意味着它确实打开了一个子外壳。
它打开的外壳有奇怪的行为,因为对于我输入的每个命令,它都会重复上述错误的四行。
我看了看,~/.bashrc
但它唯一做的就是umask 0022
。
-x
没有给我太多关于我的问题的信息
$ bash -x
+ umask 0022
++ tput bold
bash: command substitution: line 1: syntax error near unexpected token `then'
... same error
这可以链接到评论行中的'
内容吗:/ect/bashrc
if ! shopt -q login_shell ; then # We're not a login shell
# Need to redefine pathmunge, it get's undefined at the end of /etc/profile
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
我应该从这里看向哪里?我应该要求/etc/bashrc
以任何方式修复/修改吗?
编辑
正如有人建议的那样,这可能来自我的~/.profile
吗?
export PS1='$(tput bold)$(print -n "`logname`@`hostname`:$(tput sgr0)";if [[ "${PWD#$HOME}" != "$PWD" ]] then; print -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "\n$ ")'
trap 1 2 3
PATH=$PATH:$HOME/bin
export PATH
export HTTPD_HOME=/pvar/product/httpd
export EDITOR=/bin/vi
export FCEDIT=/bin/vi
export VISUAL=/bin/vi
export HISTSIZE=5000
export TMOUT=0
任何帮助表示赞赏,谢谢。
答案1
我必须更改我的.profile
以修复构建提示的行(PS1
):
export PS1='$(tput bold)$(print -n "`logname`@`hostname`:$(tput sgr0)";if [[ "${PWD#$HOME}" != "$PWD" ]] then; print -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "\n$ ")'
成为
export PS1='$(tput bold)$(echo "`logname`@`hostname`:$(tput sgr0)" ; \
if [[ "${PWD#$HOME}" != "$PWD" ]]; \
then echo "~${PWD#$HOME}"; \
else echo "${PWD}"; fi; echo "$ ")'
现在我想找到一种方法来避免echo
跳过一行(我必须替换print
为,echo
因为 bash 默认情况下不处理print
)。