已定义的shell变量或函数可以用unset取消。
删除已定义的shell变量(包括环境变量)和shell函数。
unset [option] variable
-f 只删除函数 -v 只删除变量
下面是一个用unset删除自定义变量的例子:
[peter@ibi98 ~]$ a=protein [peter@ibi98 ~]$ set |grep protein a=protein [peter@ibi98 ~]$ unset a [peter@ibi98 ~]$ set |grep protein
定义并赋值了变量a后,用set查看所有变量,会发现变量a。使用unset删除变量a后,set再查看就没有了。
使用readonly定义的只读变量不能用unset删除。