mysql chroot debian_在我的终端提示中“${debian_chroot:+($debian_chroot)}”有什么作用?...

问题描述

在我的.bashrc文件中的终端提示定义中,除此之外,我还有以下代码片段:

${debian_chroot:+($debian_chroot)}

这是做什么的,我需要它吗?

最佳解决方案

回答这个问题的重要部分是/etc/bash.bashrc的这个片段:

if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then

debian_chroot=$(cat /etc/debian_chroot)

fi

这意味着如果变量$debian_chroot为空并且文件/etc/debian_chroot存在且可读,则将变量设置为文件的内容。

现在这是为了什么?文件/etc/debian_chroot是你在另一个debian系统中有一个chroot debian系统(ubuntu基于debian)。所以这是为了更好的概述。要区分你是否在chroot。

如果您有另一个系统的chroot,例如在/srv/nfs4/netboot/中,您可以在/srv/nfs4/netboot/etc/debian_chroot中设置此chroot的名称(在我的情况下,它是一个nfs4 pxe netboot驱动器):

user@host:~# echo "netboot" >/srv/nfs4/netboot/etc/debian_chroot

然后当你在里面chroot:

chroot /srv/nfs4/netboot/

您的提示符如下所示:

(netboot)user@host:~#

次佳解决方案

通常,${var:+value}表示:

if $var is defined; then use 'value'; else do nothing

debian_chroot变量在/etc/bash.bashrc文件中定义。如果此文件存在且可读,它将获取/etc/debian_chroot文件的内容。默认情况下,此文件不存在。

有关详细信息,请参阅:

现在,为了更好地了解它到底发生了什么,请在终端中执行以下操作:

radu@Radu:~$ PS1='${var:+($var)}\u@\h:\w\$ '

radu@Radu:~$ var="test"

----

|

------------------

|

V

(test)radu@Radu:~$ var=""

radu@Radu:~$ var="and so on"

(and so on)radu@Radu:~$

第三种解决方案

如果环境变量$debian_chroot存在且不为空,则${debian_chroot:+($debian_chroot)}被($debian_chroot)(即其周围的parens的$debian_chroot的值)替换。

$debian_chroot在/etc/bash.bashrc中设置为/etc/debian_chroot的内容(如果该文件存在(默认情况下不是))并且$debian_chroot还没有值。

例如,${debian_chroot:+($debian_chroot)}通常用于对您的Bash提示进行整形

PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

顾名思义,您可以使用此变量通过将etc/debian_chroot放入chroot根文件夹来指示您所在的chroot。

如果你不知道chroot是什么机会你不需要;-)但是你仍然可以滥用它来在你的Bash提示中包含一些其他信息

默认情况下,它不执行任何操作。

参考资料

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值