为什么会出现if:〜/ .profile中的表达式语法错误?

时间:2020-10-10 15:59:07

标签: linux bash shell syntax profile

当我尝试'if: Expression syntax'时,我的.profile出现了source ~/.profile错误。我究竟做错了什么? .profile file

1 个答案:

答案 0 :(得分:0)

链接中的代码看起来“确定”,在我的bash环境中运行了“确定”,并在“ ShellCheck”中签出为“确定”。

从OP的评论中,以下内容会生成语法错误:

$ bash
$ source ./.profile
$                         <<<=== no error message, just a command prompt

这确认在.profile环境中OP的bash的内容是否正确。

从其他评论中得知:

$ echo $SHELL
/bin/tcsh

问题出在这里... tcshbash不同,这也意味着在{{1}下执行时,OP .profile中的某些命令无效}} shell。

如果我们转到Try It Online,向下滚动并选择tcsh,请输入以下代码,即可确认这一点...

tcsh

...然后运行代码,我们得到:

tty -s
if test $? = 0
then
    stty dec crt
fi

要解决此语法问题,有两种选择:

  • OP可以将默认Shell切换为if: Expression Syntax. (请参阅bash或让sysadmin更新chsh以将/etc/passwd Shell替换为tcsh贝壳);完成此操作后,所有新的登录/ shell会话都将在采购OP的bash
  • 上没有问题
  • 或...
  • OP可以在命令行上手动运行.profile,然后手动获取bash