Controlling bash Features and Options

本文介绍如何使用命令行选项及set和shopt内置命令来控制Bash的各种特性和选项,包括短选项和长选项的使用方法,以及如何启用或禁用不同类型的Shell特性。

This section explains how to controlbash features and options using command line options and the set andshopt builtins.

Command Line Options

Two kinds of command line options are available: short and long. Short options consist of a hyphen followed by a letter; long options have two hyphens followed by multiple characters. Long options must appear before short options on a command line that calls bash. Table 8-12 lists some commonly used command line options.

Table 8-12. Command line options

Option

Explanation

Syntax

Help

Displays a usage message.

--help

No edit

Prevents users from using the Readline Library (page 304) to edit command lines in an interactive shell.

--noediting

No profile

Prevents reading these startup files (page 259): /etc/profile, ~/.bash_profile, ~/.bash_login, and ~/.profile.

--noprofile

No rc

Prevents reading the ~/.bashrc startup file (page 260). This option is on by default if the shell is called as sh.

--norc

POSIX

Runs bash in POSIX mode.

--posix

Version

Displays bash version information and exits.

--version

Login

Causes bash to run as though it were a login shell.

--I (lowercase "I")

shopt

Runs a shell with the opt shopt option (page 318). A -0 (uppercase "0") sets the option; +0 unsets it.

[±]0 [ opt ]

End of options

On the command line, signals the end of options. Subsequent tokens are treated as arguments even if they begin with a hyphen (-).

Shell Features

You can control the behavior of the Bourne Again Shell by turning features on and off. Different features use different methods to turn features on and off. The set builtin controls one group of features, while the shopt builtin controls another group. You can also control many features from the command line you use to call bash.

set ±o: Turns Shell Features On and Off

The set builtin (there is a set builtin in tcsh, but it works differently), when used with the -o or +ooption, enables, disables, and lists certain bash features. For example, the following command turns on the noclobber feature (page 125):

   $ set -o noclobber

You can turn this feature off (the default) by giving the command

   $ set +o noclobber

The command set -o without an option lists each of the features controlled by set followed by its state (on or off). The command set +o without an option lists the same features in a form that you can use as input to the shell. Table 8-13 lists bash features.

Table 8-13. bash features

Feature

Description

Syntax

Alternate syntax

allexport

Automatically exports all variables and functions that you create or modify after giving this command.

set –o allexport

set –a

braceexpand

Causes bash to perform brace expansion (the default; page 323).

set –o braceexpand

set –B

cdspell

Corrects minor spelling errors in directory names used as arguments to cd.

shopt –s cdspell

 

cmdhist

Saves all lines of a multiline command in the same history entry, adding semicolons as needed.

shopt –s cmdhist

 

dotglob

Causes shell special characters (wildcards; page 133) in an ambiguous file reference to match a leading period in a filename. By default special characters do not to match a leading period. You must always specify the filenames . and ..explicitly because no pattern ever matches them.

shopt –s dotglob

 

emacs

Specifies emacs editing mode for command line editing (the default; page 305).

set –o emacs

 

errexit

Causes bash to exit when a simple command (not a control structure) fails.

set –o errexit

set –e

execfail

Causes a shell script to continue running when it cannot find the file that is given as an argument to exec. By default a script terminates whenexec cannot find the file that is given as its argument.

shopt –s execfail

 

expand_aliases

Causes aliases (page 311) to be expanded (by default it is on for interactive shells and off for noninteractive shells).

shopt –s expand_alias

 

hashall

Causes bash to remember where commands it has found using PATH (page 285) are located (default).

set –o hashall

set –h

histappend

Causes bash to append the history list to the file named by HISTFILE (page 295) when the shell exits. By default bash overwrites this file.

shopt –s histappend

 

histexpand

Causes the history mechanism (which uses exclamation points; page 299) to work (default). Turn this feature off to turn off history expansion.

set –o histexpand

set –H

history

Enable command history (on by default; page 295).

set –o history

 

ignoreeof

Specifies that bash must receive ten EOF characters before it exits. Useful on noisy dial-up lines.

set –o ignoreeof

 

monitor

Enables job control (on by default, page 272).

set –o monitor

set –m

nocaseglob

Causes ambiguous file references (page 133) to match filenames without regard to case (off by default).

shopt –s nocaseglob

 

noclobber

Helps prevent overwriting files (off by default; page 125).

set –o noclobber

set –C

noglob

Disables pathname expansion (off by default; page 133).

set –o noglob

set –f

notify

With job control (page 272) enabled, reports the termination status of background jobs immediately. The default behavior is to display the status just before the next prompt.

set –o notify

set –b

nounset

Displays an error and exits from a shell script when you use an unset variable in an interactive shell. The default is to display a null value for an unset variable.

set –o nounset

set –u

nullglob

Causes bash to expand ambiguous file references (page 133) that do not match a filename to a null string. By default bash passes these file references without expanding them.

shopt –s nullglob

 

posix

Runs bash in POSIX mode.

set –o posix

 

verbose

Displays command lines as bash reads them.

set –o verbose

set –v

vi

Specifies vi editing mode for command line editing (page 304).

set –o vi

 

xpg_echo

Causes the echo builtin to expand back-slash escape sequences without the need for the –eoption (page 548).

shopt –s xpg_echo

xtrace

Turns on shell debugging (page 536).

set –o xtrace

set –x

shopt: Turns Shell Features On and Off

The shopt (shell option) builtin (not available in tcsh) enables, disables, and lists certain bashfeatures that control the behavior of the shell. For example, the following command causes bashto include filenames that begin with a period (.) when it expands ambiguous file references (the -sstands for set):

   $ shopt -s dotglob

You can turn this feature off (the default) by giving the command (the –u stands for unset)

$ shopt -u dotglob

The shell displays how a feature is set if you give the name of the feature as the only argument toshopt:

$ shopt dotglob
dotglob           off

The command shopt without any options or arguments lists the features controlled by shopt and their state. The command shopt -s without an argument lists the features controlled by shopt that are set or on. The command shopt –u lists the features that are unset or off. Table 8-13 lists bashfeatures.

下载前可以先看下教程 https://pan.quark.cn/s/a4b39357ea24 在网页构建过程中,表单(Form)扮演着用户与网站之间沟通的关键角色,其主要功能在于汇集用户的各类输入信息。 JavaScript作为网页开发的核心技术,提供了多样化的API和函数来操作表单组件,诸如input和select等元素。 本专题将详细研究如何借助原生JavaScript对form表单进行视觉优化,并对input输入框与select下拉框进行功能增强。 一、表单基础1. 表单组件:在HTML语言中,<form>标签用于构建一个表单,该标签内部可以容纳多种表单组件,包括<input>(输入框)、<select>(下拉框)、<textarea>(多行文本输入区域)等。 2. 表单参数:诸如action(表单提交的地址)、method(表单提交的协议,为GET或POST)等属性,它们决定了表单的行为特性。 3. 表单行为:诸如onsubmit(表单提交时触发的动作)、onchange(表单元素值变更时触发的动作)等事件,能够通过JavaScript进行响应式处理。 二、input元素视觉优化1. CSS定制:通过设定input元素的CSS属性,例如border(边框)、background-color(背景色)、padding(内边距)、font-size(字体大小)等,能够调整其视觉表现。 2. placeholder特性:提供预填的提示文字,以帮助用户明确输入框的预期用途。 3. 图标集成:借助:before和:after伪元素或者额外的HTML组件结合CSS定位技术,可以在输入框中嵌入图标,从而增强视觉吸引力。 三、select下拉框视觉优化1. 复选功能:通过设置multiple属性...
【EI复现】基于深度强化学习的微能源网能量管理与优化策略研究(Python代码实现)内容概要:本文围绕“基于深度强化学习的微能源网能量管理与优化策略”展开研究,重点探讨了如何利用深度强化学习技术对微能源系统进行高效的能量管理与优化调度。文中结合Python代码实现,复现了EI级别研究成果,涵盖了微电网中分布式能源、储能系统及负荷的协调优化问题,通过构建合理的奖励函数与状态空间模型,实现对复杂能源系统的智能决策支持。研究体现了深度强化学习在应对不确定性可再生能源出力、负荷波动等挑战中的优势,提升了系统运行的经济性与稳定性。; 适合人群:具备一定Python编程基础和机器学习背景,从事能源系统优化、智能电网、强化学习应用等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于微能源网的能量调度与优化控制,提升系统能效与经济效益;②为深度强化学习在能源管理领域的落地提供可复现的技术路径与代码参考;③服务于学术研究与论文复现,特别是EI/SCI级别高水平论文的仿真实验部分。; 阅读建议:建议读者结合提供的Python代码进行实践操作,深入理解深度强化学习算法在能源系统建模中的具体应用,重点关注状态设计、动作空间定义与奖励函数构造等关键环节,并可进一步扩展至多智能体强化学习或与其他优化算法的融合研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值