Skip to content

Commit 5af632f

Browse files
authored
Update export.md
本次更新修正了格式问题(注释等)
1 parent 43458c7 commit 5af632f

1 file changed

Lines changed: 29 additions & 31 deletions

File tree

‎command/export.md‎

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export -p
1111

1212
### 主要用途
1313

14-
- 新建一到多个变量并设置导出属性。
14+
- 定义一到多个变量并设置导出属性。
1515

16-
- 修改一到多个拥有导出属性的变量的值。
16+
- 修改一到多个变量的值并设置导出属性。
1717

1818
- 删除一到多个变量的导出属性。
1919

@@ -28,34 +28,27 @@ export -p
2828

2929
#### 选项
3030

31+
```shell
32+
-f:指向函数。
33+
-n:删除变量的导出属性。
3134
-p:显示全部拥有导出属性的变量。
32-
3335
-pf:显示全部拥有导出属性的函数。
34-
35-
-n:删除变量的导出属性。
36-
37-
-nf:删除变量的导出属性。
38-
39-
-f:指向函数。
40-
36+
-nf:删除函数的导出属性。
4137
--:在它之后的选项无效。
42-
38+
```
4339

4440
#### 参数
4541

4642
name(可选):变量名或已定义函数名。
4743

4844
value(可选):变量的值。
4945

50-
51-
5246
#### 返回值
5347

5448
export返回true除非你提供了非法选项或非法名称。
5549

5650
### 例子
5751

58-
常见用法
5952
```shell
6053
# 显示全部拥有导出属性的变量。
6154
# export -p
@@ -64,40 +57,46 @@ export返回true除非你提供了非法选项或非法名称。
6457
# export -pf
6558
```
6659

67-
6860
```shell
69-
#首先删除要演示的变量名
61+
# 首先删除要演示的变量名
7062
#unset a b
71-
#新建变量的同时增加导出属性
63+
# 定义变量的同时增加导出属性
7264
export a b=3
73-
#当然也可以这样
65+
# 当然也可以先定义后增加导出属性
7466
b=3
7567
export b
7668

77-
#修改拥有导出属性的变量的值
69+
# 修改拥有导出属性的变量的值
7870
export a=5 b=7
79-
#当然也可以直接赋值修改
71+
# 当然也可以直接赋值修改
8072
a=5;b=7
8173

82-
#删除变量的导出属性
74+
# 删除变量的导出属性
8375
export -n a b
8476
```
8577

8678

87-
```
88-
#首先删除要演示的函数名
79+
```shell
80+
# 首先删除要演示的函数名
8981
unset func_1 func_2
90-
#创建函数
82+
# 创建函数
9183
function func_1(){ echo '123'; }
9284
function func_2(){ echo '890'; }
9385

94-
#为已定义函数增加导出属性
86+
# 为已定义函数增加导出属性
9587
export -f func_1 func_2
9688

97-
#删除函数的导出属性
89+
# 删除函数的导出属性
9890
export -fn a b
9991
```
10092

93+
```shell
94+
# 添加环境变量(JAVA)到`~/.bashrc`
95+
PATH=/usr/local/jdk1.7.0/bin:$PATH
96+
# 添加当前位置到动态库环境变量
97+
export LD_LIBRARY_PATH=$(pwd):${LD_LIBRARY_PATH}
98+
```
99+
101100
### 错误用法
102101

103102
- 对未定义的函数添加导出属性。
@@ -126,7 +125,7 @@ Q:我脚本文件中调用`~/.bashrc`中定义的函数和变量。为什么
126125
A:请在`~/.bashrc`文件中增加export它们的语句。另请参阅 **知识点** 段落。
127126

128127

129-
Q:列表和关联数组也可以设置导出属性吗?
128+
Q:数组和关联数组也可以设置导出属性吗?
130129

131130
A:是可以的(如果你的bash支持它们),不过有些问题( **参考链接2** )。
132131

@@ -142,7 +141,7 @@ A:因为`declare`也能够设置变量或函数的导出属性,详见`declar
142141

143142
### 知识点
144143

145-
在 `info bash`或 [bash在线文档](http://www.gnu.org/software/bash/manual/bash.html) 的
144+
在`info bash`或 [bash在线文档](http://www.gnu.org/software/bash/manual/bash.html) 的
146145
`3.7.3`节提到了shell执行环境,其中涉及变量和函数的内容如下
147146

148147
> - shell parameters that are set by variable assignment or with set or inherited from the shell’s parent in the environment
@@ -156,21 +155,20 @@ A:因为`declare`也能够设置变量或函数的导出属性,详见`declar
156155

157156
那么子shell确实继承了父shell中带有导出属性的变量或函数。
158157

159-
可参考链接 [执行脚本方式的区别](https://blog.csdn.net/soaringlee_fighting/article/details/78759448)
158+
可参考链接: [执行脚本方式的区别](https://blog.csdn.net/soaringlee_fighting/article/details/78759448)
160159

161160

162161
### 参考链接
163162

164163
1. [关于bashrc profile文件的讨论](https://www.cnblogs.com/hongzg1982/articles/2101792.html)
165164

166-
167165
2. [关于export数组的讨论](https://stackoverflow.com/questions/5564418/exporting-an-array-in-bash-script)
168166

169167
3. [export -pf用法](https://unix.stackexchange.com/questions/22796/can-i-export-functions-in-bash)
170168

171169
4. [环境变量和shell变量的区别](https://askubuntu.com/questions/26318/environment-variable-vs-shell-variable-whats-the-difference)
172170

173-
### 实例
171+
### 扩展阅读
174172

175173
一般来说,配置交叉编译工具链的时候需要指定编译工具的路径,此时就需要设置环境变量。查看已经存在的环境变量:
176174

0 commit comments

Comments
 (0)