fish和pacman:“error: Unable to read input file: 是一个目录”报错的处理

发布时间 2024-01-13 03:27:41作者: 東雲寺貍

问题描述

依照Arch Linux Wiki中,此页面介绍的方法,通过保持默认 shell 为 Bash 不变,然后添加exec fish到合适的 Bash 配置文件中,比如.bashrc,可以使得 Bash 会正常执行/etc/profile/etc/profile.d中的所有配置文件。然而,注意到,添加代码

if [[ $(ps --no-header --pid=$PPID --format=cmd) != "fish" ]]
then
    exec fish
fi

/root/.bashrc中以后(root账户的登录shell为bash),pacman安装部分软件包(例如bassh)的时候可能有如下报错:

error: Unable to read input file: 是一个目录
错误:命令未能被正确执行

亦即

error: Unable to read input file: Is a directory
error: command failed to execute correctly

并且我们注意到,只有通过sudo pacman -S bash这样的指令进行软件包安装的时候会报错,而直接登录到root账户中再pacman -S bash并不会报错。

问题解决

注释或删除/root/.bashrc中有关于exec fish的代码,仅在你目前的登录账户中添加对应代码不会影响/etc/profile/etc/profile.d的正常执行。

问题原因

sudo执行指令的时候不会执行/root/.bashrc,而登录到root账户的时候会。
问题的具体原因尚未追溯。但可以判断/root/.bashrc是直接原因。