Linux set unset命令
Linux unset命令:
功能说明:unset是一个内建的Unix shell命令,在Bourne shell家族(sh、ksh、bash等)和C shell家族(csh、tcsh等)都有实现。它可以取消设置一个shell变量,从内存和shell的导出环境中删除它。它实现为一个壳层内建指令,因为它直接操纵shell的内部。
只读shell变量不能被unset。如果试图unset只读变量,unset命令将打印一个错误消息,并返回一个非零的退出代码。
This command removes one or more variables. Each name is a variable name, specified in any of the ways acceptable to the set command. If a name refers to an element of an array then that element is removed without affecting the rest of the array. If a name consists of an array name with no parenthesized index, then the entire array is deleted. The unset command returns an empty string as result. An error occurs if any of the variables doesn't exist, and any variables after the non-existent one are not deleted.
语 法:
unset [-fv][变量或函数名称]
补充说明:unset为shell内建指令,可删除变量或函数。
参 数: -f 仅删除函数。 -v 仅删除变量。
[3][root][test:/home/root/Desktop] set lx = "ls -lh" [3][root][test:/home/root/Desktop] $lx total 80K drwxrwxr-x 2 root tt 4.0K 2014-02-19 09:32 bin drwxrwxr-x 3 root tt 4.0K 2014-02-10 10:56 Data drwxrwxr-x 2 root tt 4.0K 2014-02-19 09:32 lib drwxrwxr-x 10 root tt 4.0K 2014-02-20 16:12 script -r--r--r-- 1 root tt 312 2014-02-19 09:32 sut.cs [3][root][test:/home/root/Desktop] [3][root][test:/home/root/Desktop] [3][root][test:/home/root/Desktop] set ......此处省略输出 [3][root][test:/home/root/Desktop] set |grep -i lx lx ls -lh [3][root][test:/home/root/Desktop] [3][root][test:/home/root/Desktop] unset lx [3][root][test:/home/root/Desktop] set | grep -i lx
set命令:
Linux and Unix set command
Quick links
About set Syntax Examples Related commands Linux and Unix main page
About set
set is a built-in function of the Bourne shell (sh), C shell (csh), and Korn shell (ksh), which is used to define and determine the values of the system environment.
Syntax
Bourne shell (sh):
set [--aefhkntuvx[argument]]...
C shell (csh):
set [var[=value]]
set var [n] = word
Korn shell (ksh):
set [+-aefhkmnopstuvx] [+-o option]... [+-A name] [arg...]
Options: Bourne Shell (sh)
In sh, the set built-in command has the following options:
-- | An option of a double-dash ("--") signifies the end of an option list. This is primarily useful when values listed after the options will start with a dash themselves. |
-a | Mark variables which are modified or created for "export"; environment variables set in this way will be passed on to the environments of any subsequent commands. |
-e | Exit immediately if a command exits with a non-zero exit status. |
-f | Disable file name generation (globbing). |
-h | Locate and remember function commands as functions are defined (function commands are normally located when the function is executed). |
-k | All keyword arguments are placed in the environment for a command, not just those that precede the command name. |
-n | Read commands but do not execute them. |
-t | Exit after reading and executing one command. |
-u | Treat unset variables as an error when substituting. |
-v | Print shell input lines as they are read. |
-x | Print commands and their arguments as they are executed. |
Using + rather than - causes these flags to be turned off. These flags can also be used upon invocation of the shell itself. The current set of flags may be found in the variable $-. The remaining arguments are positional parameters and are assigned, in order, to $1, $2, .... If no arguments are given the values of all names are printed.
For each name, the unset command removes the corresponding variable or function value. The special variables PATH, PS1, PS2, MAILCHECK, and IF cannot be unset.
With the export built-in command, the given names are marked for automatic export to the environment of subsequently executed commands. If no arguments are given, variable names that have been marked for export during the current shell's execution are listed. Function names are not exported.
Options: C Shell (csh)
In csh, If no arguments are specified, set displays the values of all shell variables. Multiword values are displayed as a parenthesized list. With the var argument alone, set assigns an empty (null) value to the variable var. With arguments of the form var = value, set assigns value to var, where value is one of:
word | A single word (or quoted string). |
(wordlist) | A space-separated list of words enclosed in parentheses. |
Values are command and filename expanded before being assigned. The form set var[n]=word replaces the n'th word in a multiword value with word.
unset removes variables whose names match (using filename substitution) pattern. All variables are removed by "unset *"; this is a very bad idea if you don't know what you're doing, though.
Options: K Shell (ksh)
In ksh, the set command takes the following options:
-A | Array assignment. Unset the variable name and assign values sequentially from the list arg. If +A is used, the variable name is not unset first. | ||||||||||||||||||||||||||||||||||||||||
-a | All subsequent variables that are defined are automatically exported. | ||||||||||||||||||||||||||||||||||||||||
-e | If a command has a non-zero exit status, execute the ERR trap (if set), and exit. This mode is disabled while reading profiles. | ||||||||||||||||||||||||||||||||||||||||
-f | Disables file name generation (globbing). | ||||||||||||||||||||||||||||||||||||||||
-h | Each command becomes a tracked alias when first encountered. | ||||||||||||||||||||||||||||||||||||||||
-k | All variable assignment arguments are placed in the environment for a command, not just those that precede the command name. | ||||||||||||||||||||||||||||||||||||||||
-m | Background jobs will run in a separate process group and a line will print upon completion. The exit status of background jobs is reported in a completion message. On systems with job control, this flag is turned on automatically for interactive shells. | ||||||||||||||||||||||||||||||||||||||||
-n | Read commands and check them for syntax errors, but do not execute them. Ignored for interactive shells. | ||||||||||||||||||||||||||||||||||||||||
-o option | The option argument can be one of the following:
If no option name is supplied then the current option settings are printed. |
||||||||||||||||||||||||||||||||||||||||
-p | Disables processing of the $HOME/.profile file and uses the file /etc/suid_profile instead of the ENV file. This mode is on whenever the effective uid (user ID) is not equal to the real uid, or when the effective gid (group ID) is not equal to the real gid. Turning this off causes the effective uid and gid to be set to the real uid and gid. | ||||||||||||||||||||||||||||||||||||||||
-s | Sort the positional parameters lexicographically. | ||||||||||||||||||||||||||||||||||||||||
-t | Exit after reading and executing one command. | ||||||||||||||||||||||||||||||||||||||||
-u | Treat unset parameters as an error when substituting. | ||||||||||||||||||||||||||||||||||||||||
-v | Print shell input lines as they are read. | ||||||||||||||||||||||||||||||||||||||||
-x | Print commands and their arguments as they are executed. | ||||||||||||||||||||||||||||||||||||||||
- | Turns off -x and -v flags and stops examining arguments for flags. | ||||||||||||||||||||||||||||||||||||||||
- | Do not change any of the flags; useful in setting $1 to a value beginning with -. If no arguments follow this flag then the positional parameters are unset. |
Using + rather than - causes these flags to be turned off. These flags can also be used upon invocation of the shell. The current set of flags may be found in $-. Unless -A is specified, the remaining arguments are positional parameters and are assigned, in order, to "$1 $2 ...". If no arguments are given, then the names and values of all variables are printed on the standard output.
The variables given by the list of names are automatically unassigned: their values and attributes are erased. Readonly variables cannot be unset. If the -f flag is set, then the names refer to function names. Unsetting ERRNO, LINENO, MAILCHECK, OPTARG, OPTIND, RANDOM, SECONDS, TMOUT, and _ removes their special meaning even if they are subsequently assigned.
When using unset, the variables given by the list of names are similarly unassigned: their values and attributes are erased. Readonly variables cannot be unset. If the -f, flag is set, then the names refer to function names. Unsetting ERRNO, LINENO, MAILCHECK, OPTARG, OPTIND, RANDOM, SECONDS, TMOUT, and _ removes their special meaning even if they are subsequently assigned.
With the export built-in command, the given names are marked for automatic export to the environment of subsequently-executed commands. ksh commands that are preceded by one or two "*" characters (asterisks) are treated specially in the following ways:
- Variable assignment lists preceding the command remain in effect when the command completes.
- I/O redirections are processed after variable assignments.
- Errors cause a script that contains them to abort.
- Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed.
Examples
set PATH="/bin:/usr/bin:/usr/sbin:usr/local/bin"
In csh, this command sets the environment variable PATH, such that the shell will search for files in the /bin, /usr/bin, /usr/sbin and /usr/local/bin directories, in that order.
Related commands
Linux set unset命令的更多相关文章
- Linux系统常用命令权威指南
<一>线上查询及帮助命令(2)1.man man [选项] [命令] 查看命令帮助,命令的词典,更复杂的还有info,但不常用. #man cd-a 显示所有的手册页,不只是显示第一个-f ...
- 20165321预备作业3:Linux安装及命令入门
Linux安装 在老师给的VirtualBox的网站上面,我下载了VirtualBox的最新版本,安装成功后,我又下载了Ubuntu.但是,发现无论是哪个版本的Ubuntu都无法在VirtualBox ...
- Linux 系统常见命令功能大全_【all】
Linux常见快捷键(6个) ctrl + u:剪贴光标前面 ctrl + k:剪贴光标后面 ctrl + y:粘贴 ctrl + r:查找命令 ctrl + insert:复制 shift+ ins ...
- 20165332 预备作业三 Linux安装及命令入门
Linux安装及命令入门 一.安装Linux操作系统 由于做的比较晚,结合大多数同学的经验和娄老师的<基于VirtualBox虚拟机安装Ubuntu图文教程>,整个安装过程还算顺利,唯一遇 ...
- 【Linux】gnuplot命令大全
gnuplot命令大全 在linux命令提示符下运行gnuplot命令启动,输入quit或q或exit退出. plot命令 gnuplot> plot sin(x) with line line ...
- Linux下history命令用法
如果你经常使用 Linux 命令行,那么使用 history(历史)命令可以有效地提升你的效率.本文将通过实例的方式向你介绍 history 命令的 15 个用法. 使用 HISTTIMEFORMAT ...
- Linux下ps命令详解 Linux下ps命令的详细使用方法
http://www.jb51.net/LINUXjishu/56578.html Linux下的ps命令比较常用 Linux下ps命令详解Linux上进程有5种状态:1. 运行(正在运行或在运行队列 ...
- 例解 Linux 下 Make 命令
Linux 下 make 命令是系统管理员和程序员用的最频繁的命令之一.管理员用它通过命令行来编译和安装很多开源的工具,程序员用它来管理他们大型复杂的项目编译问题.本文我们将用一些实例来讨论 make ...
- Linux终端打印命令使用介绍
常用linux打印命令 日常使用中或shell脚本中linux终端打印命令有echo和printf. echo命令 功能说明:显示文字.语 法:echo [-ne][字符串]或 echo [--he ...
随机推荐
- AIX参数调整
AIX下修改用户最大进程数限制: 用命令查看用户进程数 ps -ef | grep 用户名|wc -l 发现用户进程数达到最大 128 查看用户最大进程数设置 命令 #lsattr -E -l sys ...
- whatweb wordpress.rb
## # This file is part of WhatWeb and may be subject to # redistribution and commercial restrictions ...
- MBCS与Unicode的转换
一.绪 其实刚开始编程的时候我不太喜欢用Unicode编码,所以比较喜欢 VC6.0,即使使用VS2010,也会设置为未设置模式. 后来,没办法的接触了些Unicode的编程的东西,必须得研究字符集的 ...
- JavaScript高级 面向对象(12)--引用类型值类型作为参数传递的特性
说明(2017-4-2 18:27:11): 1. 作为函数的参数,就是将函数的数据拷贝一份,传递给函数的定义中的参数. 函数foo()在调用的时候,做了两件事: (1)函数在调用的时候,首先需要将参 ...
- Maven 解决 下载项目 compiler 为1.5的问题
在 开发Maven 项目的时候,会发现个问题,就是下载下来的项目默认 compiler 为1.5 ,项目报错. 明明之前开发用的是1.7的啊. 这里只需要在pom.xml确定下就好了. <pro ...
- Python3 ctypes简单使用
>>> from ctypes import * >>> c_int() c_long(0) >>> c_char_p(b'hello') c_c ...
- [培训]keysight培训
DDR DDR->DDR2->DDR3->DDR4->DDR5->HBM, LPDDR(low power DDR)
- spring websocket + stomp 实现广播通信和一对一通信<转>
spring对于基于stomp协议的websocket通信,其官网上面有一个guide,但是根据guide你只能写出来广播方式的通信,不能实现一对一的通信,这篇文章在这里把广播和一对一一起整理一下给大 ...
- Android控件GridView之仿支付宝钱包首页带有分割线的GridView九宫格的完美实现
Android控件GridView之仿支付宝钱包首页带有分割线的GridView九宫格的完美实现 2015-03-10 22:38 28419人阅读 评论(17) 收藏 举报 分类: Android ...
- tomcat添加context方式部署web应用
刚巧碰到了,记录一下. 通过context的方式部署会灵活一点,不必一定指向tomcat里面的webapps目录 这种部署有几种方式: 1.在$CATALINA_BASE/conf/ server.x ...