Hed*_*ger 4 upgrade .profile bashrc syntax 18.04
Ubuntu 18.04.4(几周前从 18.04.3 自动升级)
/bin/bash
从 Gnome shell 登录后,当屏幕为纯紫色且桌面出现之前,会出现此消息:
Error found when loading /home/hfinger/.profile:
/home/hfinger/.profile: line 1: #: command not found
/home/hfinger/.bashrc: line 1: syntax error near unexpected token '('
/home/hfinger/.bashrc: line 1: '# ~/.bashrc: executed by bash(1) for non-login shells.'
As a result the session will not be configured correctly.
You should fix the problem as soon as feasible.
Run Code Online (Sandbox Code Playgroud)
问题是,有什么问题?我已经搜索过 AskUbuntu,但似乎没有人遇到过这个确切的问题。我不认为这是升级,因为在出现此问题之前它已经运行了大约一个月。
我从来没有接触过这两个文件,因为我很高兴让系统创建和配置它们。此外,我尽量让 Ubuntu 保持原样,以避免在升级到新版本后必须恢复设置。值得一提的是,以下是每个文件的第一行:
.profile, line 1: # ~/.profile: executed by the command interpreter for login shells.
.bashrc, line 1: # ~/.bashrc: executed by bash(1) for non-login shells.
Run Code Online (Sandbox Code Playgroud)
我需要如何修复这些文件?我应该提供哪些附加信息,以便比我知识渊博的人能够解决这个愚蠢的问题?
如果您的文件在开始时具有非打印字节序列(例如字节顺序标记),则可能会发生这种情况,这可能是由于在文字处理器程序或 Windows 文本编辑器中对其进行了编辑。
例如,给定
$ file profile bashrc
profile: UTF-8 Unicode (with BOM) text
bashrc: UTF-8 Unicode (with BOM) text
Run Code Online (Sandbox Code Playgroud)
(其中profile
和bashrc
是 my~/.profile
和在开头插入~/.bashrc
字节序列的本地副本0xFE 0xFF
)然后
$ bash -c 'source profile; source bashrc'
profile: line 1: #: command not found
bashrc: line 1: syntax error near unexpected token `('
bashrc: line 1: `# ~/.bashrc: executed by bash(1) for non-login shells.'
Run Code Online (Sandbox Code Playgroud)
最简单的修复方法是使用dos2unix
,默认情况下会删除 BOM:
$ dos2unix profile bashrc
dos2unix: converting file profile to Unix format...
dos2unix: converting file bashrc to Unix format...
$ file profile bashrc
profile: ASCII text
bashrc: UTF-8 Unicode text
Run Code Online (Sandbox Code Playgroud)
或者,您可以简单地用/etc/skel
您发现的目录中的新副本替换文件(尽管显然您会以这种方式丢失任何自定义)。
检查非打印字节的其他方法是
cat -A ~/.profile ~/.bashrc
Run Code Online (Sandbox Code Playgroud)
其中 BOM 将显示为控制序列,例如M-oM-;M-?#
或使用xxd
或od
直接检查字节序列
head -1 ~/.profile | od -tx1
xxd -l16 ~/.profile
Run Code Online (Sandbox Code Playgroud)
该diff
命令是有帮助的,只要确认有是有差别,但不识别的区别是什么:
$ diff profile ~/.profile
1c1
< # ~/.profile: executed by the command interpreter for login shells.
---
> # ~/.profile: executed by the command interpreter for login shells.
Run Code Online (Sandbox Code Playgroud)
检查用户 shell 的简单方法...
如果您尚未Users and Groups
安装应用程序,请按以下方式安装...
sudo apt-get update
sudo apt-get install gnome-system-tools
按Super键并输入“用户”,选择Users and Groups
应用程序,单击帐户名称,然后单击“高级设置”、“高级”选项卡,并验证/bin/bash
.
Ubuntu 18.04.4(几周前从 18.04.3 自动升级)
/bin/bash
我不知道问题是什么,但这是我解决它的方法:
$ cd ~
$ which bash
/bin/bash
$ mv .profile .profile.bak
$ mv .bashrc .bashrc.bak
$ cd /etc/skel/
$ cp .profile ~/.profile
$ cp .bashrc ~/.bashrc
Run Code Online (Sandbox Code Playgroud)
(注意:/bin/bash
是 的正确位置bash
。)
感谢大家的意见和帮助。
归档时间: |
|
查看次数: |
1881 次 |
最近记录: |