set

更改shell选项的值并设置位置参数,或显示shell变量的名称和值

语法

  set [--abefhkmnptuvxBCEHPT] [-o option-name] [argument …]
  set [+abefhkmnptuvxBCEHPT] [+o option-name] [argument …]

如果未提供任何选项或参数,则set将显示所有shell变量和函数的名称和值,这些变量和函数按照当前语言环境排序,格式可以重复用作输入。提供选项时,它们会设置或取消设置shell属性。

选项



   -a   标记为导出而修改或创建的变量. -o allexport

   -b   立即报告终止后台程序的状态,而不是在打印下一个主提示之前.  -o notify

   -B   允许符号扩展,默认选项.-o braceexpand

   -C  防止使用' `>', `>&',`<>' 的输出重定向覆盖现有文件.  -o noclobber

   -e  如果一个命令返回一个非0退出状态值(失败),就退出,除非失败的命令是until或while循环的一部分,
       if语句的一部分,&&或||列表的一部分,
       或者命令的返回状态被使用!.  -o errexit

   -f  取消使用通配符.  -o noglob

   -h  自动记录函数的所在位置
       
       默认情况下启用此选项. -o hashall

   -H  可利用"!"加<指令编号>的方式来执行history中记录的指令 -o histexpand 

   -k  指令所给的参数都会被视为此指令的环境变量. -o keyword
 
   -m  启用作业控制.  -o monitor

   -n  读取命令但不执行它们; 这可用于
       检查脚本是否存在语法错误。
       交互式shell会忽略此选项. -o noexec

   -o  如果-o没有选项名称,则打印当前选项的值
       如果+o未提供选项名称,在标准输出中显示了一系列用于重新创建当前选项设置的set命令

   -o option-name

                 allexport   同 -a.
                 braceexpand 同  -B.
                 emacs       使用emacs样式的命令行编辑界面。
                             当shell是交互式时,默认情况下启用此选项,除非使用--noediting 
                 errtrace    同 -E.
                 functrace   同 -T.
                 errexit     同 -e.
                 hashall     同 -h.
                 histexpand  同 -H.
                 history     启用命令历史记录,如上面HISTORY中所述。
                             默认情况下,此选项在交互式shell中处于启用状 
                 ignoreeof   禁止coontrol-D的方式退出shell,必须输入exit
                 keyword     同 -k.
                 monitor     同 -m.
                 noclobber   同 -C.
                 noexec      同 -n.
                 noglob      同 -f.  nolog 目前被忽略了
                 notify      同 -b.
                 nounset     同 -u.
                 onecmd      同 -t.
                 physical    同 -P.
                 pipefail    如果设置,管道的返回值是以
                             非零状态退出的最后一个(最右边)命令的值,如果管道中的所有命令都
                             成功退出,则返回零。默认情况下禁用此选项。
                 posix       更改bash的行为,其中默认操作与POSIX 
                             标准不同,以匹配标准(posix模式)。
                 privileged  同 -p.
                 verbose     同 -v.
                 vi          使用vi样式的命令行编辑界面
                 xtrace      同 -x.

   -p  启动优先顺序模式

   -P  执行指令时,会以实际的文件或目录来取代符号连接

   -t  执行完随后的指令,即退出shell。.  -o onecmd

   -u  当执行时使用到未定义过的变量,则显示错误信息. -o nounset

   -v  显示shell所读取的输入值. -o verbose

   -x  执行指令后,会先显示该指令及所下的参数. -o xtrace
  
   --  如果此选项后面没有参数,则取消设置位置参数。
       否则,位置参数被设置为参数

   -   发出选项结束信号,使所有剩余参数
       分配给位置参数。`-x'和`-v' 
       选项被关闭。如果没有参数,则位置参数
       保持不变。

除非提供了无效选项,否则返回状态始终为零

例子

设置-e和-u,使脚本在错误或未设置变量被引用时退出. 在编写和调试shell脚本时,这是一个很好的做法

#!/bin/bash
# 一个bash脚本示例
set -eu

打开allexport选项:

set -o allexport

关闭allexport选项:

set +o allexport

将shell变量'MYDEPT'设置为'Sales':

 MYDEPT=Sales
 echo $MYDEPT
要使更改成为永久更改,您可以将其导出为环境变量:

 export $MYDEPT

符号链接

默认情况下,Bash在执行更改当前目录的命令时遵循目录的符号链接。例如

如果 /usr/sys' 是/usr/local/sys’的符号链接,那么:

$ cd /usr/sys; echo $PWD
/usr/sys
$ cd ..; pwd
/usr

如果设置-P打开(不遵循符号链接),则:

$ cd /usr/sys; echo $PWD
/usr/local/sys
$ cd ..; pwd
/usr/local

调试脚本的一部分t:

set -x      # activate debugging 
# your commands go here...
set +x      # stop debugging 

set 命令实例:

linux命令:set -o vi; ls -l jnuk<ESC>bCjunk jnuk<ESC>bCjunk -l ls vi; -o set set -o vi; ls -l jnuk<ESC>bCjunkrootopen.com
linux命令:set -o vi; ls -l jnuk<ESC>bCjunk jnuk<ESC>bCjunk -l ls vi; -o set set -o vi; ls -l jnuk<ESC>bCjunkrootopen.com
2018-03-18 09:56:48

linux命令:setenv GREP_COLOR '1;37;41' '1;37;41' GREP_COLOR setenv setenv GREP_COLOR '1;37;41'rootopen.com
linux命令:setenv GREP_COLOR '1;37;41' '1;37;41' GREP_COLOR setenv setenv GREP_COLOR '1;37;41'rootopen.com
2018-03-15 22:55:48

linux命令:set -o vi vi -o set set -o virootopen.com
linux命令:set -o vi vi -o set set -o virootopen.com
2018-01-31 07:01:48

linux命令:setfacl -m u:john:r-- myfile myfile u:john:r-- -m setfacl setfacl -m u:john:r-- myfilerootopen.com
linux命令:setfacl -m u:john:r-- myfile myfile u:john:r-- -m setfacl setfacl -m u:john:r-- myfilerootopen.com
2018-01-17 13:24:48

linux命令:set -o noclobber noclobber -o set set -o noclobberrootopen.com
linux命令:set -o noclobber noclobber -o set set -o noclobberrootopen.com
2018-02-03 23:01:48

linux命令:set -o vi vi -o set set -o virootopen.com
linux命令:set -o vi vi -o set set -o virootopen.com
2018-03-23 07:22:48

linux命令:setarch i386 [command [args]] [args]] [command i386 setarch setarch i386 [command [args]]rootopen.com
linux命令:setarch i386 [command [args]] [args]] [command i386 setarch setarch i386 [command [args]]rootopen.com
2018-01-15 18:04:48

linux命令:setfont cybercafe cybercafe setfont setfont cybercaferootopen.com
linux命令:setfont cybercafe cybercafe setfont setfont cybercaferootopen.com
2018-02-28 22:32:48

linux命令:setfile -a V foo.bar; setfile -a v foo.bar; foo.bar; v -a setfile foo.bar; V -a setfile setfile -a V foo.bar; setfile -a v foo.bar;rootopen.com
linux命令:setfile -a V foo.bar; setfile -a v foo.bar; foo.bar; v -a setfile foo.bar; V -a setfile setfile -a V foo.bar; setfile -a v foo.bar;rootopen.com
2018-02-17 11:24:48

linux命令:set | fgrep " ()" ()" " fgrep | set set | fgrep " ()"rootopen.com
linux命令:set | fgrep " ()" ()" " fgrep | set set | fgrep " ()"rootopen.com
2018-03-18 21:23:48

linux命令:setterm -powersave off -blank 0 0 -blank off -powersave setterm setterm -powersave off -blank 0rootopen.com
linux命令:setterm -powersave off -blank 0 0 -blank off -powersave setterm setterm -powersave off -blank 0rootopen.com
2018-03-23 15:09:48

linux命令:setterm -bfreq 0 0 -bfreq setterm setterm -bfreq 0rootopen.com
linux命令:setterm -bfreq 0 0 -bfreq setterm setterm -bfreq 0rootopen.com
2018-01-18 13:54:48

linux命令:set -o vi vi -o set set -o virootopen.com
linux命令:set -o vi vi -o set set -o virootopen.com
2018-01-26 11:51:48

linux命令:set -o noclobber noclobber -o set set -o noclobberrootopen.com
linux命令:set -o noclobber noclobber -o set set -o noclobberrootopen.com
2018-03-08 13:07:48

linux命令:setxkbmap dvorak '' ctrl:nocaps ctrl:nocaps '' dvorak setxkbmap setxkbmap dvorak '' ctrl:nocapsrootopen.com
linux命令:setxkbmap dvorak '' ctrl:nocaps ctrl:nocaps '' dvorak setxkbmap setxkbmap dvorak '' ctrl:nocapsrootopen.com
2018-01-31 00:54:48

linux命令:setxkbmap us us setxkbmap setxkbmap usrootopen.com
linux命令:setxkbmap us us setxkbmap setxkbmap usrootopen.com
2018-01-25 23:28:48

linux命令:set -x -x set set -xrootopen.com
linux命令:set -x -x set set -xrootopen.com
2018-05-31 21:07:48

linux命令:set-proxy () { P=webproxy:1234; DU="fred"; read -p "username[$DU]:" USER; printf "%b"; UN=${USER:-$DU}; read -s -p "password:" PASS; printf "%b" "\n"; export http_proxy="http://${UN}:${PASS}@$P/"; export ftp_proxy="http://${UN}:${PASS}@$P/"; } } ftp_proxy="http://${UN}:${PASS}@$P/"; export http_proxy="http://${UN}:${PASS}@$P/"; export "\n"; "%b" printf PASS; "password:" -p -s read UN=${USER:-$DU}; "%b"; printf USER; "username[$DU]:" -p read DU="fred"; P=webproxy:1234; { () set-proxy set-proxy () { P=webproxy:1234; DU="fred"; read -p "username[$DU]:" USER; printf "%b"; UN=${USER:-$DU}; read -s -p "password:" PASS; printf "%b" "\n"; export http_proxy="http://${UN}:${PASS}@$P/"; export ftp_proxy="http://${UN}:${PASS}@$P/"; }rootopen.com
linux命令:set-proxy () { P=webproxy:1234; DU="fred"; read -p "username[$DU]:" USER; printf "%b"; UN=${USER:-$DU}; read -s -p "password:" PASS; printf "%b" "\n"; export http_proxy="http://${UN}:${PASS}@$P/"; export ftp_proxy="http://${UN}:${PASS}@$P/"; } } ftp_proxy="http://${UN}:${PASS}@$P/"; export http_proxy="http://${UN}:${PASS}@$P/"; export "\n"; "%b" printf PASS; "password:" -p -s read UN=${USER:-$DU}; "%b"; printf USER; "username[$DU]:" -p read DU="fred"; P=webproxy:1234; { () set-proxy set-proxy () { P=webproxy:1234; DU="fred"; read -p "username[$DU]:" USER; printf "%b"; UN=${USER:-$DU}; read -s -p "password:" PASS; printf "%b" "\n"; export http_proxy="http://${UN}:${PASS}@$P/"; export ftp_proxy="http://${UN}:${PASS}@$P/"; }rootopen.com
2018-03-26 04:45:48

linux命令:setopt shwordsplit shwordsplit setopt setopt shwordsplitrootopen.com
linux命令:setopt shwordsplit shwordsplit setopt setopt shwordsplitrootopen.com
2018-06-02 08:20:48

linux命令:set -eu -eu set set -eurootopen.com
linux命令:set -eu -eu set set -eurootopen.com
2018-03-05 10:20:48

linux命令:setterm -blength 0 0 -blength setterm setterm -blength 0rootopen.com
linux命令:setterm -blength 0 0 -blength setterm setterm -blength 0rootopen.com
2018-05-29 17:16:48

linux命令:setlocal enabledelayedexpansion enabledelayedexpansion setlocal setlocal enabledelayedexpansionrootopen.com
linux命令:setlocal enabledelayedexpansion enabledelayedexpansion setlocal setlocal enabledelayedexpansionrootopen.com
2018-03-12 15:27:48

linux命令:setserial -g /dev/ttyS[0-9]* | grep -v "unknown" "unknown" -v grep | /dev/ttyS[0-9]* -g setserial setserial -g /dev/ttyS[0-9]* | grep -v "unknown"rootopen.com
linux命令:setserial -g /dev/ttyS[0-9]* | grep -v "unknown" "unknown" -v grep | /dev/ttyS[0-9]* -g setserial setserial -g /dev/ttyS[0-9]* | grep -v "unknown"rootopen.com
2018-02-04 12:33:48

linux命令:set env DYLD_INSERT_LIBRARIES = /usr/lib/libgmalloc.dylib;b szone_error szone_error /usr/lib/libgmalloc.dylib;b = DYLD_INSERT_LIBRARIES env set set env DYLD_INSERT_LIBRARIES = /usr/lib/libgmalloc.dylib;b szone_errorrootopen.com
linux命令:set env DYLD_INSERT_LIBRARIES = /usr/lib/libgmalloc.dylib;b szone_error szone_error /usr/lib/libgmalloc.dylib;b = DYLD_INSERT_LIBRARIES env set set env DYLD_INSERT_LIBRARIES = /usr/lib/libgmalloc.dylib;b szone_errorrootopen.com
2018-01-24 05:51:48

linux命令:set $(ps -e o command= | grep "^/usr/bin/X "); while [ x"$1" != x"-auth" ]; do shift; done; sudo x11vnc -display :0 -auth "$2" "$2" -auth :0 -display x11vnc sudo done; shift; do ]; x"-auth" != x"$1" [ while "); "^/usr/bin/X grep | command= o -e $(ps set set $(ps -e o command= | grep "^/usr/bin/X "); while [ x"$1" != x"-auth" ]; do shift; done; sudo x11vnc -display :0 -auth "$2"rootopen.com
linux命令:set $(ps -e o command= | grep "^/usr/bin/X "); while [ x"$1" != x"-auth" ]; do shift; done; sudo x11vnc -display :0 -auth "$2" "$2" -auth :0 -display x11vnc sudo done; shift; do ]; x"-auth" != x"$1" [ while "); "^/usr/bin/X grep | command= o -e $(ps set set $(ps -e o command= | grep "^/usr/bin/X "); while [ x"$1" != x"-auth" ]; do shift; done; sudo x11vnc -display :0 -auth "$2"rootopen.com
2018-01-08 16:26:48

linux命令:set -x -x set set -xrootopen.com
linux命令:set -x -x set set -xrootopen.com
2018-04-06 18:10:48

linux命令:setxkbmap -option grp:switch,grp:alt_shift_toggle,grp_led:scroll us,es us,es grp:switch,grp:alt_shift_toggle,grp_led:scroll -option setxkbmap setxkbmap -option grp:switch,grp:alt_shift_toggle,grp_led:scroll us,esrootopen.com
linux命令:setxkbmap -option grp:switch,grp:alt_shift_toggle,grp_led:scroll us,es us,es grp:switch,grp:alt_shift_toggle,grp_led:scroll -option setxkbmap setxkbmap -option grp:switch,grp:alt_shift_toggle,grp_led:scroll us,esrootopen.com
2018-05-09 20:33:48

linux命令:set list / set nolist nolist set / list set set list / set nolistrootopen.com
linux命令:set list / set nolist nolist set / list set set list / set nolistrootopen.com
2018-05-21 06:25:48

linux命令:setxkbmap -layout us,ru -variant basic,phonetic -option -option grp:switch,grp:caps_toggle grp:switch,grp:caps_toggle -option -option basic,phonetic -variant us,ru -layout setxkbmap setxkbmap -layout us,ru -variant basic,phonetic -option -option grp:switch,grp:caps_togglerootopen.com
linux命令:setxkbmap -layout us,ru -variant basic,phonetic -option -option grp:switch,grp:caps_toggle grp:switch,grp:caps_toggle -option -option basic,phonetic -variant us,ru -layout setxkbmap setxkbmap -layout us,ru -variant basic,phonetic -option -option grp:switch,grp:caps_togglerootopen.com
2018-05-23 08:54:48

linux命令:setxkbmap it it setxkbmap setxkbmap itrootopen.com
linux命令:setxkbmap it it setxkbmap setxkbmap itrootopen.com
2018-02-21 19:49:48

linux命令:set colsep "{char}" "{char}" colsep set set colsep "{char}"rootopen.com
linux命令:set colsep "{char}" "{char}" colsep set set colsep "{char}"rootopen.com
2018-04-27 22:58:48

linux命令:setxkbmap -option ctrl:nocaps ctrl:nocaps -option setxkbmap setxkbmap -option ctrl:nocapsrootopen.com
linux命令:setxkbmap -option ctrl:nocaps ctrl:nocaps -option setxkbmap setxkbmap -option ctrl:nocapsrootopen.com
2018-05-13 02:15:48

linux命令:setserial -q /dev/ttyS0 /dev/ttyS0 -q setserial setserial -q /dev/ttyS0rootopen.com
linux命令:setserial -q /dev/ttyS0 /dev/ttyS0 -q setserial setserial -q /dev/ttyS0rootopen.com
2018-05-23 21:31:48

linux命令:set str=user_pref("browser.startup.homepage", "http://www.fcisolutions.com/"); cd = "%APPDATA%\Mozilla\Firefox\Profiles\*.default\" echo %str%>>prefs.js %str%>>prefs.js echo "%APPDATA%\Mozilla\Firefox\Profiles\*.default\" = cd "http://www.fcisolutions.com/"); str=user_pref("browser.startup.homepage", set set str=user_pref("browser.startup.homepage", "http://www.fcisolutions.com/"); cd = "%APPDATA%\Mozilla\Firefox\Profiles\*.default\" echo %str%>>prefs.jsrootopen.com
linux命令:set str=user_pref("browser.startup.homepage", "http://www.fcisolutions.com/"); cd = "%APPDATA%\Mozilla\Firefox\Profiles\*.default\" echo %str%>>prefs.js %str%>>prefs.js echo "%APPDATA%\Mozilla\Firefox\Profiles\*.default\" = cd "http://www.fcisolutions.com/"); str=user_pref("browser.startup.homepage", set set str=user_pref("browser.startup.homepage", "http://www.fcisolutions.com/"); cd = "%APPDATA%\Mozilla\Firefox\Profiles\*.default\" echo %str%>>prefs.jsrootopen.com
2018-05-10 21:59:48

linux命令:set -x && PS4='+\t ' ' PS4='+\t && -x set set -x && PS4='+\t 'rootopen.com
linux命令:set -x && PS4='+\t ' ' PS4='+\t && -x set set -x && PS4='+\t 'rootopen.com
2018-01-12 13:57:48

linux命令:setopt correct correct setopt setopt correctrootopen.com
linux命令:setopt correct correct setopt setopt correctrootopen.com
2018-02-14 11:55:48

linux命令:set -o vi vi -o set set -o virootopen.com
linux命令:set -o vi vi -o set set -o virootopen.com
2018-03-07 17:27:48

linux命令:setenforce 0 0 setenforce setenforce 0rootopen.com
linux命令:setenforce 0 0 setenforce setenforce 0rootopen.com
2018-01-04 13:24:48

linux命令:set +e +u; dd if=/dev/urandom of="/media/usb1/$$";sync;sync of="/media/usb1/$$";sync;sync if=/dev/urandom dd +u; +e set set +e +u; dd if=/dev/urandom of="/media/usb1/$$";sync;syncrootopen.com
linux命令:set +e +u; dd if=/dev/urandom of="/media/usb1/$$";sync;sync of="/media/usb1/$$";sync;sync if=/dev/urandom dd +u; +e set set +e +u; dd if=/dev/urandom of="/media/usb1/$$";sync;syncrootopen.com
2018-06-02 17:06:48

linux命令:setxkbmap -option caps:backspace caps:backspace -option setxkbmap setxkbmap -option caps:backspacerootopen.com
linux命令:setxkbmap -option caps:backspace caps:backspace -option setxkbmap setxkbmap -option caps:backspacerootopen.com
2018-02-19 00:36:48

linux命令:set -o vi vi -o set set -o virootopen.com
linux命令:set -o vi vi -o set set -o virootopen.com
2018-02-24 17:06:48

Linux的Bash命令行(A-Z排序)