【基本介绍】
set是shell的内置命令。可以用来设置修改变量,设置变量的位置
【参数介绍】
-e当还回值非0是立即退出脚本
-o设置内置环境变量
【基本使用】
1.配置环境变量
[code="linux"]
# set | head -10
BASH=/bin/bash
BASHOPTS=checkwinsize:cmdhist:expand_aliases:extquote:force_fignore:hostcomplete:interactive_comments:login_shell:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="4" [1]="1" [2]="2" [3]="1" [4]="release" [5]="x86_64-redhat-linux-gnu")
BASH_VERSION='4.1.2(1)-release'
# set +o history # To disable the history storing.
+o disables the given options.
# set -o history
-o enables the history
[/code]
2.设置变量参数及位置
[code="linux"]
# echo $1 , $2
,
# set `free | head -2 | tail -1`
# echo $1 , $2
Mem: , 1012352
# free | head -2 | tail -1
Mem: 1012352 936836 75516 0 144684 527492
[/code]
【参考引用】
[url]http://www.thegeekstuff.com/2010/08/bash-shell-builtin-commands/[/url]
set是shell的内置命令。可以用来设置修改变量,设置变量的位置
【参数介绍】
-e当还回值非0是立即退出脚本
-o设置内置环境变量
set [+abefhkmnptuvxBCEHPT] [+o option] [arg ...]
-e Exit immediately if a pipeline (which may consist of a single simple command), a subshell command enclosed in paren-
-o option-name
The option-name can be one of the following:
allexport
Same as -a.
【基本使用】
1.配置环境变量
[code="linux"]
# set | head -10
BASH=/bin/bash
BASHOPTS=checkwinsize:cmdhist:expand_aliases:extquote:force_fignore:hostcomplete:interactive_comments:login_shell:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="4" [1]="1" [2]="2" [3]="1" [4]="release" [5]="x86_64-redhat-linux-gnu")
BASH_VERSION='4.1.2(1)-release'
# set +o history # To disable the history storing.
+o disables the given options.
# set -o history
-o enables the history
[/code]
2.设置变量参数及位置
[code="linux"]
# echo $1 , $2
,
# set `free | head -2 | tail -1`
# echo $1 , $2
Mem: , 1012352
# free | head -2 | tail -1
Mem: 1012352 936836 75516 0 144684 527492
[/code]
【参考引用】
[url]http://www.thegeekstuff.com/2010/08/bash-shell-builtin-commands/[/url]