Bash shell-set bash options with built-in set and SHOPT commands

Source: Internet
Author: User
Tags posix

Set bash options with built-in set and SHOPT commands

The set command can be used to customize the shell environment, using the option "O" to turn options on or off. For example, open the options: Set-o option, close the Select item: Set +O option.

For example, to open the VI Interactive command-line edit, the following:

[Email protected] ~]#Set-o#查看当前设置情况
Allexport off
Braceexpand on
Emacs on
Errexit off
Errtrace off
Functrace off
Hashall on
Histexpand on
History on
Ignoreeof off
Interactive-comments on
Keyword off
Monitor on
Noclobber off
Noexec off
Noglob off
Nolog off
Notify off
Nounset off
Onecmd off
Physical off
Pipefail off
POSIX off
Privileged off
Verbose off
VI off#关闭中
Xtrace off
[Email protected] ~]#Set-o VI#把vi选项打开
[Email protected] ~]#Set-o#查看当前设置情况
Allexport off
Braceexpand on
Emacs off
Errexit off
Errtrace off
Functrace off
Hashall on
Histexpand on
History on
Ignoreeof off
Interactive-comments on
Keyword off
Monitor on
Noclobber off
Noexec off
Noglob off
Nolog off
Notify off
Nounset off
Onecmd off
Physical off
Pipefail off
POSIX off
Privileged off
Verbose off
VI on#已经打开
Xtrace off

Built-in SET command options

Option name Quick Switch Meaning
Allexport -A Starting with this option, the new variable or modified variable to be output is automatically marked until the option is reset
Braceexpand -B Open curly brace extension, which is a default setting
Emacs command line editing using the Emacs built-in editor is a default setting
Errexit -E Exits when the command returns a non-0 exit state (failed). Do not set when reading initialization file
Histexpand -H Perform history replace when open!!! Extension, is a default setting
History Open command-line history, open by default
Ignoreeof Disable the use of the EOF (CTRL+D) key to exit the shell. You must type exit to exit. Equivalent to setting the shell variable ignoreeof=10
Keyword -K Place keyword arguments in the environment of the command
Interactive-comments For interactive shells, use the text after the # symbol as a comment
Monitor -M Set up Job control
Noclobber -C Prevent files from being rewritten when redirected
Noexec -N Read the command, but do not execute it. The syntax used to check the script. Interactive runtime does not open
Noglob -D Extension with pathname is forbidden. The wildcard character is turned off
Notify -B Notifies the user when a background job completes
Nounset -U An error message appears when you extend an undefined variable
Onecmd -T Exit after reading and executing commands
Physical -P When set, type the CD or PWD Forbidden symbolic link. Replace with a physical directory
Privileged -P When set, the shell does not read the. Profile or env file, and the Shell function is not inherited from the environment, and privileges are automatically opened for the setuid script
Verbose -V Open verbose mode for debugging
Vi command line editing using the VI built-in editor
Xtrace -X Turn on Echo mode for debugging


The shopt command is an alternative to the set command, many of which are the same as the set command, but it adds a lot of options. You can use the "-P" option to view the settings for the shopt option. The "-u" switch indicates a reset option, and "-S" indicates that the option is currently set.

[Email protected] ~]# shopt-p #查看当前设置情况
Shopt-u Cdable_vars
Shopt-u Cdspell
Shopt-u Checkhash
Shopt-s checkwinsize
Shopt-s cmdhist
Shopt-u Dotglob
Shopt-u Execfail
Shopt-s expand_aliases
Shopt-u Extdebug
Shopt-u Extglob
Shopt-s Extquote
Shopt-u Failglob
Shopt-s Force_fignore
Shopt-u gnu_errfmt
Shopt-u Histreedit
Shopt-u Histappend
Shopt-u histverify
Shopt-s Hostcomplete
Shopt-u Huponexit
Shopt-s interactive_comments
Shopt-u lithist
Shopt-s Login_shell
Shopt-u Mailwarn
Shopt-u no_empty_cmd_completion
Shopt-u Nocaseglob
Shopt-u Nullglob
Shopt-s Progcomp
Shopt-s Promptvars
Shopt-u Restricted_shell
Shopt-u Shift_verbose
Shopt-s SourcePath
Shopt-u Xpg_echo

[Email protected] ~]#shopt-s Cdspell#把cdspell选项打开
[Email protected] ~]#shopt-p Cdspell#打印cdspell设置
Shopt-s Cdspell
[Email protected] ~]#Cd/raot#故意拼写错误
/root
[Email protected] ~]#pwd#查看当前目录
/root
[[Email protected] ~]# CD/usr/loca/bin#故意拼写错误
/usr/local/bin
[Email protected] bin]#pwd#查看当前目录
/usr/local/bin
[Email protected] bin]#shopt-u Cdspell#把cdspell选项打开
[Email protected] bin]#shopt-p Cdspell#打印cdspell设置
Shopt-u Cdspell
[Email protected] bin]#Cd/raot#故意拼写错误
-BASH:CD:/raot: There is no file or directory #进入目录错误

shopt command Options

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/4D/C9/wKiom1RZwxeiVbE_AAbeDmATTQA475.jpg "style=" float: none; "title=" 1.png "alt=" Wkiom1rzwxeivbe_aabedmattqa475.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/4D/C8/wKioL1RZw3mDwq5KAALb_ZTv-XM899.jpg "style=" float: none; "title=" 2.png "alt=" Wkiol1rzw3mdwq5kaalb_ztv-xm899.jpg "/>


This article is from the "Professor" blog, please be sure to keep this source http://professor.blog.51cto.com/996189/1572113

Bash shell-set bash options with built-in set and SHOPT commands

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.