gpt4 book ai didi

bash - 我怎么知道我是否在子 shell 中

转载 作者:行者123 更新时间:2023-11-29 09:02:12 25 4
gpt4 key购买 nike

如果我正在使用 bash 并键入 bash 我在子 shell 中并且需要键入 exit 以返回到原始父 shell。如果我忘记了我在哪一个,我该如何检查?

最佳答案

使用SHLVL 环境变量。

ma​​n bash:

SHLVL : Incremented by one each time an instance of bash is started.

$ echo "$SHLV"
1

$ bash

$ echo "$SHLV"
2

$ exit

$ echo "$SHLV"
1

关于bash - 我怎么知道我是否在子 shell 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44351904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com