linux shell内建命令declare

详细参考

man bash中的SHELL BUILTIN COMMANDS

declare [-aAfFgilnrtux] [-p] [name[=value] ...]
       typeset [-aAfFgilnrtux] [-p] [name[=value] ...]
              Declare  variables  and/or give them attributes.  If no names are given then display the values of variables.  The -p option will display the attributes and values of each
              name.  When -p is used with name arguments, additional options, other than -f and -F, are ignored.  When -p is  supplied  without  name  arguments,  it  will  display  the
              attributes  and  values  of  all  variables  having the attributes specified by the additional options.  If no other options are supplied with -p, declare will display the
              attributes and values of all shell variables.  The -f option will restrict the display to shell functions.  The -F option inhibits the  display  of  function  definitions;
              only  the  function  name and attributes are printed.  If the extdebug shell option is enabled using shopt, the source file name and line number where each name is defined
              are displayed as well.  The -F option implies -f.  The -g option forces variables to be created or modified at the global scope, even when declare is executed in  a  shell
              function.   It  is  ignored  in  all  other  cases.   The  following  options can be used to restrict output to variables with the specified attribute or to give variables
              attributes:
              -a     Each name is an indexed array variable (see Arrays above).
              -A     Each name is an associative array variable (see Arrays above).
              -f     Use function names only.
              -i     The variable is treated as an integer; arithmetic evaluation (see ARITHMETIC EVALUATION above) is performed when the variable is assigned a value.
              -l     When the variable is assigned a value, all upper-case characters are converted to lower-case.  The upper-case attribute is disabled.
              -n     Give each name the nameref attribute, making it a name reference to another variable.  That other variable is defined by the value of name.  All references, assign‐
                     ments,  and  attribute modifications to name, except those using or changing the -n attribute itself, are performed on the variable referenced by name‘s value.  The
                     nameref attribute cannot be applied to array variables.
              -r     Make names readonly.  These names cannot then be assigned values by subsequent assignment statements or unset.
              -t     Give each name the trace attribute.  Traced functions inherit the DEBUG and RETURN traps from the calling shell.  The trace attribute has  no  special  meaning  for
                     variables.
              -u     When the variable is assigned a value, all lower-case characters are converted to upper-case.  The lower-case attribute is disabled.
              -x     Mark names for export to subsequent commands via the environment.

              Using  `+‘  instead  of  `-‘  turns off the attribute instead, with the exceptions that +a may not be used to destroy an array variable and +r will not remove the readonly
              attribute.  When used in a function, declare and typeset make each name local, as with the local command, unless the -g option is supplied.  If a variable name is followed
              by  =value, the value of the variable is set to value.  When using -a or -A and the compound assignment syntax to create array variables, additional attributes do not take
              effect until subsequent assignments.  The return value is 0 unless an invalid option is encountered, an attempt is made to define  a  function  using  ``-f  foo=bar‘‘,  an
              attempt  is  made  to  assign  a  value to a readonly variable, an attempt is made to assign a value to an array variable without using the compound assignment syntax (see
              Arrays above), one of the names is not a valid shell variable name, an attempt is made to turn off readonly status for a readonly variable, an attempt is made to turn  off
              array status for an array variable, or an attempt is made to display a non-existent function with -f.

原文地址:https://www.cnblogs.com/longchang/p/11584599.html

时间: 2024-11-29 12:32:26

linux shell内建命令declare的相关文章

Bash Shell内建命令和保留字

Bash Shell内建命令和保留字命令含义!保留字,逻辑非:不做任何事,只做参数展开.读取文件并在shell中执行它alias设置命令或命令行别名bg将作业置于后台运行bind将关键字序列与readline函数或宏捆绑break保留字,跳出for.while.until.select循环builtin调用命令的内建命令格式,而禁用同名的函数.或者同名的扩展命令case保留字,多重选择cd切换当前工作目录command找出内建和外部命令:寻找内建命令而非同名函数continue保留字,到达下次f

启用或关闭shell内建命令

查看命令的类型:type [[email protected] ~]# type cd cd is a shell builtin [[email protected] ~]# type ls ls is aliased to `ls --color=auto' [[email protected] ~]# type -a ls ls is aliased to `ls --color=auto' ls is /bin/ls [[email protected] ~]# 查看系统上是否有内建命令

shell学习笔记之一(shell内建命令)

注释: # 注意:shell 文件开头的#!/bin/bash 里的#不是注释 运行: 1.bash shell.sh 2.chmod +x shell.sh -> ./shell.sh 3.添加到PATH 变量中 4.. ./shell.sh 排错: 1.语法错误 运行时会有提示 2.逻辑错误 使用echo 打印, sleep number:睡眠number 秒,降低循环速度 使用bash -x 来调试shell 脚本 第三方工具:bashdb 内建命令: 1.判断一个命令是否是内建的:typ

bourne again shell内建命令

内建命令(build-in commands)是shell build-in的命令,当内建命令使用的时候,shell将会直接执行,无需新建子进程.内建命令被用来创建一些功能性的或者便捷性的组建. bash支持3中类型的内建命令 Bourne Shell build-ins : , . break cd continue eval exec exit export getopts hash pwd readonly return set shift test [ times trap umask

Shell 内建命令 shopt extglob 选项

简介 shopt 命令可以设置 shell 的可选参数. shopt [-psu] [optname …] -s 开启某个选项. -u 关闭某个选项. -p 列出所有可设置的选项. extglob选项 如果开启 extglob 选项, shell 将启用模式匹配. 可参考 ■ Shell 模式匹配 查看 extglob 选项是否开启(默认是off) $ shopt extglob extglob off 开启 extglob 选项 $ shopt -s extglob 此时查看 extglob

Shell所有内建命令

参考自 Linux命令大全 查看shell命令是否是shell内建命令,可使用type来判断: $ type cdcd is a shell builtin$ type pingping is /bin/ping 所有的内建命令如下: sh shell命令解释器 trap 指定在接收到信号后将要采取的动作 let 简单的计算器 seq 以指定增量从首数开始打印数字到尾数 tput 通过terminfo数据库对终端会话进行初始化和操作 apropos 在 whatis 数据库中查找字符串 set

Linux - Bash shell的功能;内建命令type

命令编修能力 (history): bash 的功能里头,相当棒的一个就是『他能记忆使用过的命令!』 这功能真的相当的棒!因为我只要在命令列按『上下键』就可以找到前/后一个输入的命令!而在很多 distribution 里头,默认的命令记忆功能可以到达 1000 个!也就是说, 你曾经下达过的命令几乎都被记录下来了. 这么多的命令记录在哪里呢?在你的家目录内的 .bash_history 啦! 不过,需要留意的是,~/.bash_history 记录的是前一次登陆以前所运行过的命令, 而至于这一

Linux Shell的父子关系及内建命令

Linux Shell的父子关系及内建命令 Shell的类型 系统启动什么样的shell程序取决于你个人的用户ID配置.在/etc/passwd文件中,在用户ID记录的第7个字段中列出了默认的shell程序.只要用户登录到某个虚拟控制台终端或是在GUI中启动终端仿真器,默认的shell程序就会开始运行. 在下面的例子中,用户xiaoyu使用了GNU bash shell作为自己的默认shell程序: 1 [email protected]:/$ cat /etc/passwd 2 [...] 3

Linux内建命令

内建命令 内建命令指的就是包含在 Bash 工具集中的命令.这主要是考虑到执行效率的问题--内建命令将比外部命令的执行得更快,外部命令通常需要 fork 出一个单独的进程来执行.另外一部分原因是特定的内建命令需要直接存取 shell 内核部分. 一个内建命令通常与一个系统命令同名,但是 Bash 在内部重新实现了这些命令.比如,Bash 的 echo 命令与 /bin/echo 就不尽相同,虽然它们的行为绝大多数情况下是一样的. 关键字的意思就是保留字.对于 shell 来说关键字有特殊的含义,