gpt4 book ai didi

linux - bash环境变量$-中的字符是什么意思?

转载 作者:IT王子 更新时间:2023-10-29 00:24:08 25 4
gpt4 key购买 nike

我一直在查看各种 Linux 发行版附带的一些 .bashrc 和 .profile 脚本,发现有时它们会检查 $-

这是 Ubuntu 中的一个

case $- in
*i*) ;;
*) return;;
esac

在这种情况下,它会检查是否存在“i”标志以查看当前 shell 是否是交互式 shell。

我当前的 session 给了我这个:

# echo $-
himBH

其他标志/选项是什么意思?某处有完整的 list 吗?

最佳答案

来自 man bash :

-

Expands to the current option flags as specified upon invocation, by the set builtin command, or those set by the shell itself (such as the -i option).

所以这些是控制 shell 行为的当前选项。特别是:

  • h:二进制文件在 $PATH 中的缓存位置。加快执行速度,但如果您在 shell session 期间四处移动二进制文件,则会失败。
  • i: 当前shell是交互式的
  • m: Job control已启用
  • B:Brace expansion已启用
  • H: History substitution!-1

关于linux - bash环境变量$-中的字符是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18146443/

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