Shell 系列之 declare 与 typeset
来源:互联网 发布:apache 不允许列目录 编辑:程序博客网 时间:2024/06/05 14:43
目录结构:
命令用途
常用命令参数
使用示例
命令用途
declare 与 typeset 命令是bash的内建命令,两者是完全一样的,用来声明shell变量,设置变量的属性。
常用命令参数
-r 设置变量为只读
-i 设置变量为整数
-a 设置变量为数组array
-f 如果后面没有参数的话会列出之前脚本定义的所有函数,如果有参数的话列出以参数命名的函数
-x 设置变量在脚本外也可以访问到
使用示例
#!/bin/bashfunc1 (){ echo This is a function.}declare -f # Lists the function above.echodeclare -i var1 # var1 is an integer.var1=2367echo "var1 declared as $var1"var1=var1+1 # Integer declaration eliminates the need for 'let'.echo "var1 incremented by 1 is $var1."# Attempt to change variable declared as integer.echo "Attempting to change var1 to floating point value, 2367.1."var1=2367.1 # Results in error message, with no change to variable.echo "var1 is still $var1"echodeclare -r var2=13.36 # 'declare' permits setting a variable property #+ and simultaneously assigning it a value.echo "var2 declared as $var2" # Attempt to change readonly variable.var2=13.37 # Generates error message, and exit from script.echo "var2 is still $var2" # This line will not execute.exit 0 # Script will not exit here.
参考文献:
Advanced Bash-Scripting Guide
linux bash shell之declare
end!
0 0
- Shell 系列之 declare 与 typeset
- declare与typeset命令
- 【Bash百宝箱】shell内建命令之declare、typeset、local
- shell 知识点补充(1)-提示字符的设定/read/declare / typeset/变量设定功能/别名/万用字符与特殊符号
- Linux学习- declare / typeset 声明变量类型与属性
- 【linux学习笔记】bash学习之declare/typeset
- shell 之 declare
- shell实例(八) ---指定变量类型:使用declare或typeset,随机数
- Linux--shell typeset
- linux bash shell之declare
- linux bash shell之declare
- Linux Shell之declare命令
- linux bash shell之declare
- linux bash shell之declare
- linux bash shell之declare
- Linux bash shell之declare
- shell typeset命令的使用
- shell 中typeset 的用法
- Matlab_learning_4(rand randn randint函数 )
- 嵌入式开发环境搭建----win10+VMware RHEL6 +mini2440
- 用GDB调试程序(四)
- Android工具类--SharedPreferences储存类
- HDU 5552 (CDQ分治 NTT)
- Shell 系列之 declare 与 typeset
- ajax
- MyBatis mapper文件中的变量引用方式#{}与${}的差别
- Java中删除文件、删除目录及目录下所有文件
- 写了2个小游戏项目斗地主,麻将
- 关于递归的若干问题
- mvn配置
- 258. Add Digits
- interface f0/0与interface serial0/0的区别