bash环境变量$-中的字符是什么意思? [英] What do the characters in the bash environment variable $- mean?

查看:160
本文介绍了bash环境变量$-中的字符是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been looking through some of the .bashrc and .profile scripts that come with various Linux distros and am seeing that sometimes they check $-.

这是Ubuntu中的一个

Here's one in Ubuntu

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

在这种情况下,它正在检查是否存在"i"标志,以查看当前外壳是否为交互式外壳.

In this case it's checking for the "i" flag is present to see if the current shell is an interactive one.

我当前的课程是给我的:

My current session gives me this :

# echo $-
himBH

其他标志/选项是什么意思?哪里有完整的清单?

What are the other flags/options mean? Is there a comprehensive list somewhere?

推荐答案

来自 man bash :

-

通过内置的设置扩展为调用时指定的当前选项标志命令或由外壳程序本身设置的命令(例如-i选项).

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行为的当前选项.特别是:

So these are the current options that control the behavior of the shell. In particular:

  • h:$PATH中二进制文件的缓存位置.加快执行速度,但是如果您在Shell会话期间四处移动二进制文件,则会失败.
  • i:当前的shell是交互式的
  • m:作业控制已启用
  • B:括号扩展已启用
  • H:历史替换,如
  • h: Cache location of binaries in the $PATH. Speeds up execution, but fails if you move binaries around during the shell session.
  • i: The current shell is interactive
  • m: Job control is enabled
  • B: Brace expansion is enabled
  • H: History substitution like !-1

这篇关于bash环境变量$-中的字符是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆